Submission #1079829

# Submission time Handle Problem Language Result Execution time Memory
1079829 2024-08-29T02:16:59 Z kustizus Examination (JOI19_examination) C++17
100 / 100
425 ms 55040 KB
// #pragma GCC optimize("O3","unroll-loops")
#include <bits/stdc++.h>
#define int long long
using namespace std;
mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=2e5;
struct Node{
    int x,y,s,ty;
};
vector <Node> v;
int n,q,ans[N+5];
void Rs(int l, int r){
    int md=l+r>>1;
    int x=l,y=md+1;
    vector <Node> dq;
    while (x<=md || y<=r){
        if (x>md) dq.push_back(v[y++]);
        else if (y>r) dq.push_back(v[x++]);
        else if (v[x].y<v[y].y) dq.push_back(v[x++]);
        else dq.push_back(v[y++]);
    }
    for (int i=r;i>=l;--i){
        v[i]=dq.back();
        dq.pop_back();
    }
}
bool comp(Node a, Node b){
    if (a.x!=b.x) return a.x<b.x;
    if (a.y!=b.y) return a.y<b.y;
    if (a.s!=b.s) return a.s<b.s;
    return a.ty>b.ty;
}
struct Fenwick_Tree{
    int FT[N+5];
    void clear(){
        for (int i=1;i<=N;++i) FT[i]=0;
    }
    void Update(int idx, int val){
        for (;idx<=N;idx+=idx&(-idx)) FT[idx]+=val;
    }
    int Get(int idx){
        int val=0;
        for (;idx;idx-=idx&(-idx)) val+=FT[idx];
        return val;
    }
    int Sum(int l, int r){
        return Get(r)-Get(l-1);
    }
} fw;
void dnc(int l, int r){
    if (l>=r) return;
    int md=l+r>>1;
    dnc(l,md);
    dnc(md+1,r);
    int pointer=md+1;
    for (int i=md+1;i<=r;++i) 
        if (!v[i].ty) fw.Update(v[i].s,1);
    for (int i=l;i<=md;++i){
        while (pointer<=r && v[pointer].y<v[i].y){
            if (!v[pointer].ty) fw.Update(v[pointer].s,-1);
            ++pointer;
        }
        if (v[i].ty) ans[v[i].ty]+=fw.Sum(v[i].s,N);
    }
    for (int i=pointer;i<=r;++i)
        if (!v[i].ty) fw.Update(v[i].s,-1);
    Rs(l,r);
}
void Solve(){
    cin>>n>>q;
    v.push_back({0,0,0,0});
    for (int i=1;i<=n;++i){
        int x,y;
        cin>>x>>y;
        v.push_back({x,y,x+y,0});
    }
    for (int i=1;i<=q;++i){
        int x,y,z;
        cin>>x>>y>>z;
        v.push_back({x,y,z,i});
    }
    sort(v.begin()+1,v.end(),comp);
    map <int,int> mp,cnt;
    for (int i=1;i<=n+q;++i) mp[v[i].s]=1;
    int idx=0;
    for (pair <int,int> x : mp)
        cnt[x.first]=++idx;
    for (int i=1;i<=n+q;++i) v[i].s=cnt[v[i].s];
    // for (int i=1;i<=n+q;++i) cout<<v[i].x<<' '<<v[i].y<<' '<<v[i].s<<"\n";
    // cout<<"\n";
    dnc(1,n+q);
    for (int i=1;i<=q;++i) cout<<ans[i]<<"\n";
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (fopen("file.inp","r")){
        freopen ("file.inp","r",stdin);
        freopen ("file.out","w",stdout);
    }
    int t=1;
    // cin>>t;
    while (t--) Solve();
    cerr<<"\nTIME: "<<1000*clock()/CLOCKS_PER_SEC <<"ms.";
}

Compilation message

examination.cpp: In function 'void Rs(long long int, long long int)':
examination.cpp:13:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 |     int md=l+r>>1;
      |            ~^~
examination.cpp: In function 'void dnc(long long int, long long int)':
examination.cpp:52:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |     int md=l+r>>1;
      |            ~^~
examination.cpp: In function 'int main()':
examination.cpp:98:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen ("file.inp","r",stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
examination.cpp:99:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         freopen ("file.out","w",stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 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 0 ms 2396 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 9 ms 1952 KB Output is correct
8 Correct 11 ms 1948 KB Output is correct
9 Correct 10 ms 3872 KB Output is correct
10 Correct 8 ms 3836 KB Output is correct
11 Correct 7 ms 3872 KB Output is correct
12 Correct 5 ms 2984 KB Output is correct
13 Correct 9 ms 3500 KB Output is correct
14 Correct 7 ms 3616 KB Output is correct
15 Correct 7 ms 3540 KB Output is correct
16 Correct 5 ms 3488 KB Output is correct
17 Correct 7 ms 4004 KB Output is correct
18 Correct 7 ms 1056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 281 ms 35132 KB Output is correct
2 Correct 279 ms 35012 KB Output is correct
3 Correct 285 ms 33964 KB Output is correct
4 Correct 220 ms 33852 KB Output is correct
5 Correct 240 ms 32756 KB Output is correct
6 Correct 156 ms 21404 KB Output is correct
7 Correct 265 ms 35328 KB Output is correct
8 Correct 257 ms 33128 KB Output is correct
9 Correct 253 ms 32536 KB Output is correct
10 Correct 199 ms 34316 KB Output is correct
11 Correct 194 ms 31284 KB Output is correct
12 Correct 172 ms 21060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 281 ms 35132 KB Output is correct
2 Correct 279 ms 35012 KB Output is correct
3 Correct 285 ms 33964 KB Output is correct
4 Correct 220 ms 33852 KB Output is correct
5 Correct 240 ms 32756 KB Output is correct
6 Correct 156 ms 21404 KB Output is correct
7 Correct 265 ms 35328 KB Output is correct
8 Correct 257 ms 33128 KB Output is correct
9 Correct 253 ms 32536 KB Output is correct
10 Correct 199 ms 34316 KB Output is correct
11 Correct 194 ms 31284 KB Output is correct
12 Correct 172 ms 21060 KB Output is correct
13 Correct 357 ms 42116 KB Output is correct
14 Correct 352 ms 41424 KB Output is correct
15 Correct 266 ms 36348 KB Output is correct
16 Correct 267 ms 36920 KB Output is correct
17 Correct 280 ms 36824 KB Output is correct
18 Correct 160 ms 24192 KB Output is correct
19 Correct 359 ms 40056 KB Output is correct
20 Correct 342 ms 38972 KB Output is correct
21 Correct 334 ms 39948 KB Output is correct
22 Correct 188 ms 32464 KB Output is correct
23 Correct 205 ms 32960 KB Output is correct
24 Correct 166 ms 24136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 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 0 ms 2396 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 9 ms 1952 KB Output is correct
8 Correct 11 ms 1948 KB Output is correct
9 Correct 10 ms 3872 KB Output is correct
10 Correct 8 ms 3836 KB Output is correct
11 Correct 7 ms 3872 KB Output is correct
12 Correct 5 ms 2984 KB Output is correct
13 Correct 9 ms 3500 KB Output is correct
14 Correct 7 ms 3616 KB Output is correct
15 Correct 7 ms 3540 KB Output is correct
16 Correct 5 ms 3488 KB Output is correct
17 Correct 7 ms 4004 KB Output is correct
18 Correct 7 ms 1056 KB Output is correct
19 Correct 281 ms 35132 KB Output is correct
20 Correct 279 ms 35012 KB Output is correct
21 Correct 285 ms 33964 KB Output is correct
22 Correct 220 ms 33852 KB Output is correct
23 Correct 240 ms 32756 KB Output is correct
24 Correct 156 ms 21404 KB Output is correct
25 Correct 265 ms 35328 KB Output is correct
26 Correct 257 ms 33128 KB Output is correct
27 Correct 253 ms 32536 KB Output is correct
28 Correct 199 ms 34316 KB Output is correct
29 Correct 194 ms 31284 KB Output is correct
30 Correct 172 ms 21060 KB Output is correct
31 Correct 357 ms 42116 KB Output is correct
32 Correct 352 ms 41424 KB Output is correct
33 Correct 266 ms 36348 KB Output is correct
34 Correct 267 ms 36920 KB Output is correct
35 Correct 280 ms 36824 KB Output is correct
36 Correct 160 ms 24192 KB Output is correct
37 Correct 359 ms 40056 KB Output is correct
38 Correct 342 ms 38972 KB Output is correct
39 Correct 334 ms 39948 KB Output is correct
40 Correct 188 ms 32464 KB Output is correct
41 Correct 205 ms 32960 KB Output is correct
42 Correct 166 ms 24136 KB Output is correct
43 Correct 410 ms 53332 KB Output is correct
44 Correct 423 ms 51796 KB Output is correct
45 Correct 425 ms 51680 KB Output is correct
46 Correct 341 ms 52028 KB Output is correct
47 Correct 356 ms 53312 KB Output is correct
48 Correct 156 ms 23456 KB Output is correct
49 Correct 387 ms 55040 KB Output is correct
50 Correct 389 ms 52424 KB Output is correct
51 Correct 369 ms 53304 KB Output is correct
52 Correct 323 ms 49928 KB Output is correct
53 Correct 224 ms 40260 KB Output is correct