Submission #1079864

# Submission time Handle Problem Language Result Execution time Memory
1079864 2024-08-29T02:46:16 Z KhoaDuy Examination (JOI19_examination) C++14
100 / 100
538 ms 38320 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
struct cube{
    int a,b,c,idx;
};
const int MAXN=1e5;
int ans[MAXN]={0};
int bit[2*MAXN+1]={0};
void update(int i,int x){
    for(;i<=2*MAXN;i+=(i&(-i))){
        bit[i]+=x;
    }
}
int pre(int i){
    int curr=0;
    for(;i;i-=(i&(-i))){
        curr+=bit[i];
    }
    return curr;
}
int query(int l,int r){
    return pre(r)-pre(l-1);
}
bool cmp(cube &a,cube &b){
    return (a.b>b.b);
}
bool cmp2(cube &a,cube &b){
    if(a.a!=b.a){
        return (a.a<b.a);
    }
    if(a.idx!=b.idx){
        return (a.idx>b.idx);
    }
}
void dnc(vector<cube> &v){
    if(v.size()<=1){
        return;
    }
    int mid=(v.size()>>1);
    vector<cube> v1,v2;
    for(int i=0;i<mid;i++){
        v1.push_back(v[i]);
    }
    for(int i=mid;i<v.size();i++){
        v2.push_back(v[i]);
    }
    dnc(v1),dnc(v2);
    sort(v.begin(),v.end(),cmp);
    /*cout << "GOT" << endl;
    cout << "V1: " << endl;
    for(int i=0;i<v1.size();i++){
        cout << v1[i].a << ' ' << v1[i].b << ' ' << v1[i].c << ' ' << v1[i].idx << endl;
    }
    cout << "V2: " << endl;
    for(int i=0;i<v2.size();i++){
        cout << v2[i].a << ' ' << v2[i].b << ' ' << v2[i].c << ' ' << v2[i].idx << endl;
    }*/
    int ptr=0;
    for(int i=0;i<v2.size();i++){
        while(ptr<v1.size()&&v1[ptr].b>v2[i].b){
            if(v1[ptr].idx!=-1){
                ans[v1[ptr].idx]+=query(v1[ptr].c,2*MAXN);
            }
            ptr++;
        }
        if(v2[i].idx==-1){
            update(v2[i].c,1);
        }
    }
    while(ptr<v1.size()){
        if(v1[ptr].idx!=-1){
            ans[v1[ptr].idx]+=query(v1[ptr].c,2*MAXN);
        }
        ptr++;
    }
    for(int i=0;i<v2.size();i++){
        if(v2[i].idx==-1){
            update(v2[i].c,-1);
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,q;
    cin >> n >> q;
    vector<cube> v;
    map<int,int> mp;
    for(int i=0;i<n;i++){
        int s,t;
        cin >> s >> t;
        v.push_back({s,t,s+t,-1});
        mp[s+t]=1;
    }
    for(int i=0;i<q;i++){
        int x,y,z;
        cin >> x >> y >> z;
        v.push_back({x,y,z,i});
        mp[z]=1;
    }
    int idx=1;
    for(pair<const int,int> &x:mp){
        x.second=idx;
        idx++;
    }
    for(int i=0;i<v.size();i++){
        v[i].c=mp[v[i].c];
    }
    for(int i=0;i<v.size();i++){
    //    cout << v[i].a << ' ' << v[i].b << ' ' << v[i].c << ' ' << v[i].idx << endl;
    }
    sort(v.begin(),v.end(),cmp2);
    dnc(v);
    for(int i=0;i<q;i++){
        cout << ans[i] << endl;
    }
}

Compilation message

examination.cpp: In function 'void dnc(std::vector<cube>&)':
examination.cpp:46:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i=mid;i<v.size();i++){
      |                   ~^~~~~~~~~
examination.cpp:61:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int i=0;i<v2.size();i++){
      |                 ~^~~~~~~~~~
examination.cpp:62:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         while(ptr<v1.size()&&v1[ptr].b>v2[i].b){
      |               ~~~^~~~~~~~~~
examination.cpp:72:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     while(ptr<v1.size()){
      |           ~~~^~~~~~~~~~
examination.cpp:78:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for(int i=0;i<v2.size();i++){
      |                 ~^~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:108:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
examination.cpp:111:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
examination.cpp: In function 'bool cmp2(cube&, cube&)':
examination.cpp:36:1: warning: control reaches end of non-void function [-Wreturn-type]
   36 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 9 ms 1496 KB Output is correct
8 Correct 10 ms 1496 KB Output is correct
9 Correct 10 ms 1496 KB Output is correct
10 Correct 8 ms 1496 KB Output is correct
11 Correct 9 ms 1392 KB Output is correct
12 Correct 6 ms 992 KB Output is correct
13 Correct 9 ms 3360 KB Output is correct
14 Correct 9 ms 3288 KB Output is correct
15 Correct 9 ms 3288 KB Output is correct
16 Correct 7 ms 1240 KB Output is correct
17 Correct 7 ms 3544 KB Output is correct
18 Correct 7 ms 1052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 418 ms 28596 KB Output is correct
2 Correct 446 ms 28480 KB Output is correct
3 Correct 410 ms 30896 KB Output is correct
4 Correct 319 ms 28336 KB Output is correct
5 Correct 401 ms 27564 KB Output is correct
6 Correct 256 ms 24504 KB Output is correct
7 Correct 396 ms 28676 KB Output is correct
8 Correct 402 ms 27820 KB Output is correct
9 Correct 384 ms 29264 KB Output is correct
10 Correct 407 ms 26904 KB Output is correct
11 Correct 296 ms 27624 KB Output is correct
12 Correct 231 ms 23064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 418 ms 28596 KB Output is correct
2 Correct 446 ms 28480 KB Output is correct
3 Correct 410 ms 30896 KB Output is correct
4 Correct 319 ms 28336 KB Output is correct
5 Correct 401 ms 27564 KB Output is correct
6 Correct 256 ms 24504 KB Output is correct
7 Correct 396 ms 28676 KB Output is correct
8 Correct 402 ms 27820 KB Output is correct
9 Correct 384 ms 29264 KB Output is correct
10 Correct 407 ms 26904 KB Output is correct
11 Correct 296 ms 27624 KB Output is correct
12 Correct 231 ms 23064 KB Output is correct
13 Correct 478 ms 31404 KB Output is correct
14 Correct 469 ms 32176 KB Output is correct
15 Correct 403 ms 28332 KB Output is correct
16 Correct 395 ms 29028 KB Output is correct
17 Correct 451 ms 28588 KB Output is correct
18 Correct 267 ms 25272 KB Output is correct
19 Correct 494 ms 32220 KB Output is correct
20 Correct 538 ms 31864 KB Output is correct
21 Correct 488 ms 31516 KB Output is correct
22 Correct 409 ms 27564 KB Output is correct
23 Correct 288 ms 26284 KB Output is correct
24 Correct 227 ms 22200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 9 ms 1496 KB Output is correct
8 Correct 10 ms 1496 KB Output is correct
9 Correct 10 ms 1496 KB Output is correct
10 Correct 8 ms 1496 KB Output is correct
11 Correct 9 ms 1392 KB Output is correct
12 Correct 6 ms 992 KB Output is correct
13 Correct 9 ms 3360 KB Output is correct
14 Correct 9 ms 3288 KB Output is correct
15 Correct 9 ms 3288 KB Output is correct
16 Correct 7 ms 1240 KB Output is correct
17 Correct 7 ms 3544 KB Output is correct
18 Correct 7 ms 1052 KB Output is correct
19 Correct 418 ms 28596 KB Output is correct
20 Correct 446 ms 28480 KB Output is correct
21 Correct 410 ms 30896 KB Output is correct
22 Correct 319 ms 28336 KB Output is correct
23 Correct 401 ms 27564 KB Output is correct
24 Correct 256 ms 24504 KB Output is correct
25 Correct 396 ms 28676 KB Output is correct
26 Correct 402 ms 27820 KB Output is correct
27 Correct 384 ms 29264 KB Output is correct
28 Correct 407 ms 26904 KB Output is correct
29 Correct 296 ms 27624 KB Output is correct
30 Correct 231 ms 23064 KB Output is correct
31 Correct 478 ms 31404 KB Output is correct
32 Correct 469 ms 32176 KB Output is correct
33 Correct 403 ms 28332 KB Output is correct
34 Correct 395 ms 29028 KB Output is correct
35 Correct 451 ms 28588 KB Output is correct
36 Correct 267 ms 25272 KB Output is correct
37 Correct 494 ms 32220 KB Output is correct
38 Correct 538 ms 31864 KB Output is correct
39 Correct 488 ms 31516 KB Output is correct
40 Correct 409 ms 27564 KB Output is correct
41 Correct 288 ms 26284 KB Output is correct
42 Correct 227 ms 22200 KB Output is correct
43 Correct 531 ms 36528 KB Output is correct
44 Correct 521 ms 37552 KB Output is correct
45 Correct 524 ms 36960 KB Output is correct
46 Correct 429 ms 38080 KB Output is correct
47 Correct 490 ms 35756 KB Output is correct
48 Correct 261 ms 22708 KB Output is correct
49 Correct 509 ms 38320 KB Output is correct
50 Correct 513 ms 36784 KB Output is correct
51 Correct 519 ms 36272 KB Output is correct
52 Correct 505 ms 35500 KB Output is correct
53 Correct 288 ms 28592 KB Output is correct