fork download
  1. //FRUSTRATED
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define pb push_back
  5. #define mp make_pair
  6. #define ll long long
  7. #define fi(filename) freopen(filename, "r", stdin)
  8. #define F(i,a,n) for(int i=(a);i<(n);++i)
  9. #define S(x) scanf("%d",&x)
  10. #define Pl(x) printf("%lld\n",x)
  11. #define fr first
  12. #define se second
  13. #define all(x) x.begin(),x.end()
  14. int maxval;
  15. int tree[100000007];
  16. ll read(int idx){
  17. ll sum = 0;
  18. while (idx > 0){
  19. sum += tree[idx];
  20. idx -= (idx & -idx);
  21. }
  22. return sum;
  23. }
  24. void update(int idx ,int val){
  25. while (idx <= maxval){
  26. tree[idx] += val;
  27. idx += (idx & -idx);
  28. }
  29. }
  30. int main() {
  31. // fi("input.txt");
  32. int n,m,ct=0;
  33. ll ans=0;
  34. int col;
  35. double x1,x2,y,y1,y2,x;
  36. int xx1,xx2,yy,yy1,yy2,xx,prev;
  37. S(n);
  38. pair<int,int> pt;
  39. vector<int> dell;
  40. vector< pair<pair<pair<int,int>,int>,pair<int,int> > > temp;
  41. vector< pair<pair<int,int>,int> > vect;
  42. F(i,0,n) {
  43. scanf("%lf%lf%lf",&x1,&x2,&y);
  44. xx1=x1*10000000;
  45. xx2=x2*10000000;
  46. yy=y*10000000;
  47. xx1+=1;xx2+=1;yy+=1;
  48. if(xx1>xx2) swap(xx1,xx2);
  49. vect.pb(mp(mp(xx1,0),yy));
  50. vect.pb(mp(mp(xx2,3),yy));
  51. maxval=max(maxval,yy);
  52. }
  53. F(i,0,n) {
  54. scanf("%lf%lf%lf",&y1,&y2,&x);
  55. yy1=y1*10000000;
  56. yy2=y2*10000000;
  57. xx=x*10000000;
  58. yy1+=1;yy2+=1;xx+=1;
  59. if(yy1>yy2) swap(yy1,yy2);
  60. vect.pb(mp(mp(xx,2),yy1));
  61. temp.pb(mp(mp(mp(xx,2),yy1),mp(xx,yy2)));
  62. maxval=max(maxval,yy1);
  63. maxval=max(maxval,yy2);
  64. }
  65. maxval+=5;
  66. sort(all(vect));
  67. sort(all(temp));
  68. n=vect.size();
  69. prev=-1;
  70. F(i,0,n) {
  71. xx1=vect[i].fr.fr;yy1=vect[i].se;
  72. col=vect[i].fr.se;
  73. if(xx1!=prev) {
  74. m=dell.size();
  75. F(j,0,m) {
  76. update(dell[j],-1);
  77. }
  78. dell.clear();
  79. }
  80. if(col==0) {
  81. update(yy1,1);
  82. }
  83. else if(col==3) {
  84. prev==xx1;
  85. dell.pb(yy1);
  86. }
  87. else {
  88. pt=temp[ct].se;
  89. yy2=pt.se;
  90. ans=ans+read(yy2)-read(yy1-1);
  91. ++ct;
  92. }
  93. }
  94. Pl(ans);
  95. return 0;
  96. }
Success #stdin #stdout 0s 394112KB
stdin
Standard input is empty
stdout
0