Submission #1033799

# Submission time Handle Problem Language Result Execution time Memory
1033799 2024-07-25T06:32:20 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
563 ms 39460 KB
#include <bits/stdc++.h>
 
#define int long long
#define ll long long
#define pb push_back
 
using namespace std;
 
struct point{
    int a, b, c, id, val;
};
vector<point> student;
const int maxn = 1e6 + 10;
int ans[maxn];
 
bool cmp(point x, point y){
    if(x.a != y.a) return x.a > y.a;
    if(x.b != y.b) return x.b < y.b;
    return x.c < y.c;
}
 
void inv(point &a){
    a.a = -a.a;
    a.b = -a.b;
    a.c = -a.c;
}
 
int bit[maxn];
 
int getsum(int i){
    ll sum = 0;
    while(i > 0){
        sum+=bit[i];
        i-=(i & (-i));
    }
    return sum;
}
 
void update(int i, int v){
    while(i < maxn){
        bit[i]+=v;
        i+=(i & (-i));
    }
}
 
void dnc(int l, int r){
    if(l + 1 == r) return;
    int mid = (l + r)/2;
    dnc(l , mid); dnc(mid, r);
    vector<pair<int,int>> rec; vector<point> tmp;
    int a = l, b = mid, sum = 0;
 
    while(a < mid && b < r) {
        if(student[a].b > student[b].b){
            update(student[a].c, student[a].val);
            sum+=student[a].val;
            rec.push_back({student[a].c,student[a].val});
            tmp.push_back(student[a++]);
        }
        else{
            ans[student[b].id] += sum - getsum(student[b].c);
            tmp.push_back(student[b++]);
        }
    }
    while(a < mid) tmp.push_back(student[a++]);
    while(b < r) ans[student[b].id] += sum - getsum(student[b].c), tmp.push_back(student[b++]);
    for(int i = l ; i < r ; ++i) student[i] = tmp[i - l];
 
    for(auto x: rec) update(x.first, -x.second);
    vector<pair<int,int>> ().swap(rec);
    vector<point> ().swap(tmp);
}
 
 
signed main(){
    int n, q;
    cin >> n >> q;
    vector<int> compress;
    compress.pb(-1e18); compress.pb(1e18);
    for(int i = 0; i < n; i++){
        point tmp; cin >> tmp.a >> tmp.b;
        tmp.c = tmp.a + tmp.b; tmp.id = 0; tmp.val = 1;
        // inv(tmp);
        compress.pb(tmp.a);compress.pb(tmp.b);compress.pb(tmp.c);
        student.pb(tmp);
    }
 
    int cnt = 1;
    int _q = q;
    while(q--){
        point tmp;
        cin >> tmp.a >> tmp.b >> tmp.c;
        tmp.a--; tmp.b--; tmp.c--;
        tmp.val = 0 ;
        compress.pb(tmp.a); compress.pb(tmp.b); compress.pb(tmp.c);
        tmp.id = cnt;
        // inv(tmp);
        cnt++;
        student.pb(tmp);
    }
    sort(compress.begin(),compress.end());
    for(auto &x : student){
        x.a = lower_bound(compress.begin(),compress.end(),x.a) - compress.begin();
        x.b = lower_bound(compress.begin(),compress.end(),x.b) - compress.begin();
        x.c = lower_bound(compress.begin(),compress.end(),x.c) - compress.begin();
    }
    sort(student.begin(),student.end(), cmp);
 
    dnc(0, n + _q);
 
    for(int i = 1; i <= _q; i++){
        cout << ans[i] << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 11 ms 1488 KB Output is correct
8 Correct 17 ms 1488 KB Output is correct
9 Correct 11 ms 1484 KB Output is correct
10 Correct 10 ms 1488 KB Output is correct
11 Correct 8 ms 1428 KB Output is correct
12 Correct 6 ms 1432 KB Output is correct
13 Correct 11 ms 1488 KB Output is correct
14 Correct 12 ms 1488 KB Output is correct
15 Correct 11 ms 1488 KB Output is correct
16 Correct 7 ms 1356 KB Output is correct
17 Correct 9 ms 1484 KB Output is correct
18 Correct 5 ms 1352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 493 ms 35768 KB Output is correct
2 Correct 461 ms 35928 KB Output is correct
3 Correct 430 ms 35620 KB Output is correct
4 Correct 393 ms 34120 KB Output is correct
5 Correct 298 ms 34128 KB Output is correct
6 Correct 233 ms 32332 KB Output is correct
7 Correct 400 ms 35660 KB Output is correct
8 Correct 453 ms 35652 KB Output is correct
9 Correct 425 ms 35408 KB Output is correct
10 Correct 252 ms 34128 KB Output is correct
11 Correct 333 ms 34132 KB Output is correct
12 Correct 190 ms 31792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 493 ms 35768 KB Output is correct
2 Correct 461 ms 35928 KB Output is correct
3 Correct 430 ms 35620 KB Output is correct
4 Correct 393 ms 34120 KB Output is correct
5 Correct 298 ms 34128 KB Output is correct
6 Correct 233 ms 32332 KB Output is correct
7 Correct 400 ms 35660 KB Output is correct
8 Correct 453 ms 35652 KB Output is correct
9 Correct 425 ms 35408 KB Output is correct
10 Correct 252 ms 34128 KB Output is correct
11 Correct 333 ms 34132 KB Output is correct
12 Correct 190 ms 31792 KB Output is correct
13 Correct 468 ms 36436 KB Output is correct
14 Correct 483 ms 36392 KB Output is correct
15 Correct 485 ms 35948 KB Output is correct
16 Correct 426 ms 35152 KB Output is correct
17 Correct 377 ms 35124 KB Output is correct
18 Correct 247 ms 32108 KB Output is correct
19 Correct 520 ms 36568 KB Output is correct
20 Correct 493 ms 36420 KB Output is correct
21 Correct 489 ms 36420 KB Output is correct
22 Correct 272 ms 34180 KB Output is correct
23 Correct 395 ms 34176 KB Output is correct
24 Correct 211 ms 31836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 11 ms 1488 KB Output is correct
8 Correct 17 ms 1488 KB Output is correct
9 Correct 11 ms 1484 KB Output is correct
10 Correct 10 ms 1488 KB Output is correct
11 Correct 8 ms 1428 KB Output is correct
12 Correct 6 ms 1432 KB Output is correct
13 Correct 11 ms 1488 KB Output is correct
14 Correct 12 ms 1488 KB Output is correct
15 Correct 11 ms 1488 KB Output is correct
16 Correct 7 ms 1356 KB Output is correct
17 Correct 9 ms 1484 KB Output is correct
18 Correct 5 ms 1352 KB Output is correct
19 Correct 493 ms 35768 KB Output is correct
20 Correct 461 ms 35928 KB Output is correct
21 Correct 430 ms 35620 KB Output is correct
22 Correct 393 ms 34120 KB Output is correct
23 Correct 298 ms 34128 KB Output is correct
24 Correct 233 ms 32332 KB Output is correct
25 Correct 400 ms 35660 KB Output is correct
26 Correct 453 ms 35652 KB Output is correct
27 Correct 425 ms 35408 KB Output is correct
28 Correct 252 ms 34128 KB Output is correct
29 Correct 333 ms 34132 KB Output is correct
30 Correct 190 ms 31792 KB Output is correct
31 Correct 468 ms 36436 KB Output is correct
32 Correct 483 ms 36392 KB Output is correct
33 Correct 485 ms 35948 KB Output is correct
34 Correct 426 ms 35152 KB Output is correct
35 Correct 377 ms 35124 KB Output is correct
36 Correct 247 ms 32108 KB Output is correct
37 Correct 520 ms 36568 KB Output is correct
38 Correct 493 ms 36420 KB Output is correct
39 Correct 489 ms 36420 KB Output is correct
40 Correct 272 ms 34180 KB Output is correct
41 Correct 395 ms 34176 KB Output is correct
42 Correct 211 ms 31836 KB Output is correct
43 Correct 523 ms 36448 KB Output is correct
44 Correct 510 ms 39460 KB Output is correct
45 Correct 536 ms 39296 KB Output is correct
46 Correct 408 ms 37172 KB Output is correct
47 Correct 353 ms 36896 KB Output is correct
48 Correct 212 ms 33360 KB Output is correct
49 Correct 501 ms 39304 KB Output is correct
50 Correct 563 ms 39324 KB Output is correct
51 Correct 485 ms 39288 KB Output is correct
52 Correct 316 ms 36948 KB Output is correct
53 Correct 429 ms 35980 KB Output is correct