답안 #839438

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839438 2023-08-30T03:11:30 Z huutuan Examination (JOI19_examination) C++14
100 / 100
487 ms 61320 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define sumof(x) accumulate(all(x), 0ll)

struct nigga{
   int x, y, z, i;
   nigga(int a=0, int b=0, int c=0, int d=0): x(a), y(b), z(c), i(d){}
   bool operator<(const nigga &a) const {
      return make_pair(z, i)<make_pair(a.z, a.i);
   }
};

const int N=2e5+1;
int n, q, ans[N];
nigga a[N];
vector<int> node[N];
vector<int> t[N];

void fake_update(int x, int y){
   for (int i=x; i<N; i+=i&-i) node[i].push_back(y);
}

void update(int x, int y){
   for (int i=x; i<N; i+=i&-i)
      for (int j=lower_bound(all(node[i]), y)-node[i].begin()+1; j<=sz(node[i]); j+=j&-j) ++t[i][j];
}

int get(int x, int y){
   int res=0;
   for (int i=x; i; i-=i&-i)
      for (int j=upper_bound(all(node[i]), y)-node[i].begin(); j; j-=j&-j) res+=t[i][j];
   return res;
}

void solve(int tc){
   // cout << "Case #" << tc << ": ";
   cin >> n >> q;
   vector<int> r, c;
   for (int i=1; i<=n; ++i) cin >> a[i].x >> a[i].y, a[i].x*=-1, a[i].y*=-1, a[i].z=a[i].x+a[i].y, r.push_back(a[i].x), c.push_back(a[i].y), a[i].i=i;
   for (int i=n+1; i<=n+q; ++i) cin >> a[i].x >> a[i].y >> a[i].z, a[i].x*=-1, a[i].y*=-1, a[i].z*=-1, r.push_back(a[i].x), c.push_back(a[i].y), a[i].i=i;
   sort(all(r)); sort(all(c)); r.resize(unique(all(r))-r.begin()); c.resize(unique(all(c))-c.begin());
   for (int i=1; i<=n+q; ++i) a[i].x=lower_bound(all(r), a[i].x)-r.begin()+1, a[i].y=lower_bound(all(c), a[i].y)-c.begin()+1;
   for (int i=1; i<=n; ++i) fake_update(a[i].x, a[i].y);
   sort(a+1, a+n+q+1);
   for (int i=1; i<N; ++i){
      node[i].push_back(-1);
      node[i].push_back(1e9);
      sort(all(node[i]));
      node[i].resize(unique(all(node[i]))-node[i].begin());
      t[i].resize(sz(node[i])+1);
   }
   for (int i=1; i<=n+q; ++i){
      if (a[i].i<=n) update(a[i].x, a[i].y);
      else ans[a[i].i-n]=get(a[i].x, a[i].y);
   }
   for (int i=1; i<=q; ++i) cout << ans[i] << '\n';
}

int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   int ntests=1;
   // cin >> ntests;
   for (int i=1; i<=ntests; ++i) solve(i);
   return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 28496 KB Output is correct
2 Correct 32 ms 28480 KB Output is correct
3 Correct 32 ms 28500 KB Output is correct
4 Correct 32 ms 28412 KB Output is correct
5 Correct 34 ms 28412 KB Output is correct
6 Correct 32 ms 28492 KB Output is correct
7 Correct 44 ms 29260 KB Output is correct
8 Correct 43 ms 29208 KB Output is correct
9 Correct 44 ms 29208 KB Output is correct
10 Correct 41 ms 29100 KB Output is correct
11 Correct 41 ms 29596 KB Output is correct
12 Correct 39 ms 29156 KB Output is correct
13 Correct 43 ms 29284 KB Output is correct
14 Correct 43 ms 29260 KB Output is correct
15 Correct 43 ms 29268 KB Output is correct
16 Correct 42 ms 29480 KB Output is correct
17 Correct 39 ms 29004 KB Output is correct
18 Correct 38 ms 29024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 427 ms 51588 KB Output is correct
2 Correct 437 ms 51652 KB Output is correct
3 Correct 446 ms 51668 KB Output is correct
4 Correct 209 ms 46080 KB Output is correct
5 Correct 325 ms 56832 KB Output is correct
6 Correct 159 ms 48312 KB Output is correct
7 Correct 415 ms 50216 KB Output is correct
8 Correct 410 ms 51644 KB Output is correct
9 Correct 404 ms 50180 KB Output is correct
10 Correct 311 ms 56408 KB Output is correct
11 Correct 187 ms 45112 KB Output is correct
12 Correct 108 ms 46868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 427 ms 51588 KB Output is correct
2 Correct 437 ms 51652 KB Output is correct
3 Correct 446 ms 51668 KB Output is correct
4 Correct 209 ms 46080 KB Output is correct
5 Correct 325 ms 56832 KB Output is correct
6 Correct 159 ms 48312 KB Output is correct
7 Correct 415 ms 50216 KB Output is correct
8 Correct 410 ms 51644 KB Output is correct
9 Correct 404 ms 50180 KB Output is correct
10 Correct 311 ms 56408 KB Output is correct
11 Correct 187 ms 45112 KB Output is correct
12 Correct 108 ms 46868 KB Output is correct
13 Correct 477 ms 51648 KB Output is correct
14 Correct 473 ms 51712 KB Output is correct
15 Correct 460 ms 51640 KB Output is correct
16 Correct 226 ms 46076 KB Output is correct
17 Correct 350 ms 56828 KB Output is correct
18 Correct 168 ms 48240 KB Output is correct
19 Correct 474 ms 51624 KB Output is correct
20 Correct 476 ms 51720 KB Output is correct
21 Correct 443 ms 50804 KB Output is correct
22 Correct 305 ms 56436 KB Output is correct
23 Correct 176 ms 45056 KB Output is correct
24 Correct 109 ms 46924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 28496 KB Output is correct
2 Correct 32 ms 28480 KB Output is correct
3 Correct 32 ms 28500 KB Output is correct
4 Correct 32 ms 28412 KB Output is correct
5 Correct 34 ms 28412 KB Output is correct
6 Correct 32 ms 28492 KB Output is correct
7 Correct 44 ms 29260 KB Output is correct
8 Correct 43 ms 29208 KB Output is correct
9 Correct 44 ms 29208 KB Output is correct
10 Correct 41 ms 29100 KB Output is correct
11 Correct 41 ms 29596 KB Output is correct
12 Correct 39 ms 29156 KB Output is correct
13 Correct 43 ms 29284 KB Output is correct
14 Correct 43 ms 29260 KB Output is correct
15 Correct 43 ms 29268 KB Output is correct
16 Correct 42 ms 29480 KB Output is correct
17 Correct 39 ms 29004 KB Output is correct
18 Correct 38 ms 29024 KB Output is correct
19 Correct 427 ms 51588 KB Output is correct
20 Correct 437 ms 51652 KB Output is correct
21 Correct 446 ms 51668 KB Output is correct
22 Correct 209 ms 46080 KB Output is correct
23 Correct 325 ms 56832 KB Output is correct
24 Correct 159 ms 48312 KB Output is correct
25 Correct 415 ms 50216 KB Output is correct
26 Correct 410 ms 51644 KB Output is correct
27 Correct 404 ms 50180 KB Output is correct
28 Correct 311 ms 56408 KB Output is correct
29 Correct 187 ms 45112 KB Output is correct
30 Correct 108 ms 46868 KB Output is correct
31 Correct 477 ms 51648 KB Output is correct
32 Correct 473 ms 51712 KB Output is correct
33 Correct 460 ms 51640 KB Output is correct
34 Correct 226 ms 46076 KB Output is correct
35 Correct 350 ms 56828 KB Output is correct
36 Correct 168 ms 48240 KB Output is correct
37 Correct 474 ms 51624 KB Output is correct
38 Correct 476 ms 51720 KB Output is correct
39 Correct 443 ms 50804 KB Output is correct
40 Correct 305 ms 56436 KB Output is correct
41 Correct 176 ms 45056 KB Output is correct
42 Correct 109 ms 46924 KB Output is correct
43 Correct 474 ms 51048 KB Output is correct
44 Correct 487 ms 51276 KB Output is correct
45 Correct 478 ms 51264 KB Output is correct
46 Correct 254 ms 46124 KB Output is correct
47 Correct 347 ms 61220 KB Output is correct
48 Correct 162 ms 48108 KB Output is correct
49 Correct 467 ms 52844 KB Output is correct
50 Correct 458 ms 51244 KB Output is correct
51 Correct 442 ms 52616 KB Output is correct
52 Correct 328 ms 61320 KB Output is correct
53 Correct 207 ms 45088 KB Output is correct