fork download
  1. // author : anphung
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define file "TRIANGLE"
  5. #define int64 long long
  6. #define f0(i,a,b) for(int (i) = (a); (i) <= (b); ++i)
  7. #define TIME (1.0*clock()/CLOCKS_PER_SEC)
  8. #define pb push_back
  9. #define all(a) (a).begin(),(a).end()
  10.  
  11. int n;
  12.  
  13.  
  14. int32_t main(){
  15. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  16. freopen(file".inp","r",stdin);
  17. freopen(file".out","w",stdout);
  18.  
  19. cin>>n;
  20. vector<int> r, g, b;
  21. f0(i,0,n-1){
  22. char c;int d;
  23. cin>>c>>d;
  24. if(c=='r'){
  25. r.pb(d);
  26. }else if(c=='g')g.pb(d);
  27. else b.pb(d);
  28. }
  29.  
  30. sort(all(r));
  31. sort(all(g));
  32. sort(all(b));
  33.  
  34. int cnt = 0;
  35. for(auto &x:r){
  36. for(auto &y:g){
  37. int lo = abs(x-y)+1, hi = x+y-1;
  38. if(lo>hi)continue;
  39.  
  40. int lb = lower_bound(b.begin(),b.end(),lo) - b.begin();
  41. int ub = upper_bound(b.begin(),b.end(),hi) - b.begin();
  42.  
  43. cnt += (ub-lb);
  44. }
  45. }
  46.  
  47. cout<<cnt;
  48. //cerr<<"\ntime elapsed: "<<TIME <<"s.\n";
  49. }
  50.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty