답안 #887000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887000 2023-12-13T12:13:26 Z imarn Examination (JOI19_examination) C++14
100 / 100
623 ms 77384 KB
#include "bits/stdc++.h"
#define f first
#define s second
#define ll long long
#define pb push_back
#define pii pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
using namespace std;
const int N=1e5+5;
struct query{
    ll i,x,y,z;
    bool operator<(const query &o)const{return x>o.x;}
};
struct fenwick{
    vector<ll>v,fw;
    void build(){
        fw.resize(v.size()+1,0);
    }
    void upd(ll i){
        i = upper_bound(all(v),i)-v.begin();
        //cout<<i<<"\n";
        for(;i<sz(fw);i+=i&-i)fw[i]++;
    }
    int qr(ll i,int res=0){
        i = upper_bound(all(v),i)-v.begin();
        for(;i;i-=i&-i)res+=fw[i];
        return res;
    }
}t[4*N];
pii b[N];
ll c[N];
void build(int i,int l,int r){
    if(l==r){
        t[i].v.pb(b[l].s+b[l].f);t[i].build();
        return;
    }int m=(l+r)>>1;
    build(2*i,l,m);build(2*i+1,m+1,r);
    int li=0,ri=0;
    while(li<t[2*i].v.size()&&ri<t[2*i+1].v.size()){
        if(t[2*i].v[li]<t[2*i+1].v[ri])t[i].v.pb(t[2*i].v[li++]);
        else t[i].v.pb(t[2*i+1].v[ri++]);
    }while(li<t[2*i].v.size())t[i].v.pb(t[2*i].v[li++]);
    while(ri<t[2*i+1].v.size())t[i].v.pb(t[2*i+1].v[ri++]);
    t[i].build();
}
void upd(int i,int l,int r,int idx,ll v){
    if(r<idx||l>idx)return;
    if(l==r){
        t[i].upd(v);return;
    }
    int m=(l+r)>>1;
    upd(2*i,l,m,idx,v);upd(2*i+1,m+1,r,idx,v);
    t[i].upd(v);
}
int qr(int i,int l,int r,int tl,int tr,ll v){
    if(r<tl||l>tr)return 0;
    if(r<=tr&&l>=tl){
        return t[i].qr(v);
    }int m=(l+r)>>1;
    return qr(2*i,l,m,tl,tr,v)+qr(2*i+1,m+1,r,tl,tr,v);
}
map<pii,pii>mp;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,q;cin>>n>>q;
    for(int i=1;i<=n;i++)cin>>b[i].s>>b[i].f,c[i]=b[i].f,mp[{b[i].s,b[i].f}].s=b[i].f+b[i].s;
    sort(b+1,b+1+n);sort(c+1,c+n+1);build(1,1,n);
    for(int i=n;i>=1;i--)mp[{b[i].s,b[i].f}].f=i,swap(b[i].f,b[i].s);sort(b+1,b+n+1);
    query qq[q];
    for(int i=0;i<q;i++)cin>>qq[i].x>>qq[i].y>>qq[i].z,qq[i].i=i;
    sort(qq,qq+q);
    int ans[q];int j=n;
    for(int i=0;i<q;i++){
        while(j>0&&b[j].f>=qq[i].x){
            int id=lower_bound(c+1,c+n+1,b[j].s)-c;
            upd(1,1,n,mp[{b[j].f,b[j].s}].f,mp[{b[j].f,b[j].s}].s);
            j--;
        }int id=lower_bound(c+1,c+1+n,qq[i].y)-c;
        ans[qq[i].i] = qr(1,1,n,id,n,1e16)-qr(1,1,n,id,n,qq[i].z-1);
    }for(int i=0;i<q;i++)cout<<ans[i]<<"\n";
}

Compilation message

examination.cpp: In function 'void build(int, int, int)':
examination.cpp:40:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     while(li<t[2*i].v.size()&&ri<t[2*i+1].v.size()){
      |           ~~^~~~~~~~~~~~~~~~
examination.cpp:40:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     while(li<t[2*i].v.size()&&ri<t[2*i+1].v.size()){
      |                               ~~^~~~~~~~~~~~~~~~~~
examination.cpp:43:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     }while(li<t[2*i].v.size())t[i].v.pb(t[2*i].v[li++]);
      |            ~~^~~~~~~~~~~~~~~~
examination.cpp:44:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     while(ri<t[2*i+1].v.size())t[i].v.pb(t[2*i+1].v[ri++]);
      |           ~~^~~~~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:69:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   69 |     for(int i=n;i>=1;i--)mp[{b[i].s,b[i].f}].f=i,swap(b[i].f,b[i].s);sort(b+1,b+n+1);
      |     ^~~
examination.cpp:69:70: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   69 |     for(int i=n;i>=1;i--)mp[{b[i].s,b[i].f}].f=i,swap(b[i].f,b[i].s);sort(b+1,b+n+1);
      |                                                                      ^~~~
examination.cpp:76:17: warning: unused variable 'id' [-Wunused-variable]
   76 |             int id=lower_bound(c+1,c+n+1,b[j].s)-c;
      |                 ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21336 KB Output is correct
2 Correct 4 ms 21340 KB Output is correct
3 Correct 4 ms 21340 KB Output is correct
4 Correct 4 ms 21280 KB Output is correct
5 Correct 4 ms 21340 KB Output is correct
6 Correct 5 ms 21340 KB Output is correct
7 Correct 13 ms 22620 KB Output is correct
8 Correct 13 ms 22620 KB Output is correct
9 Correct 12 ms 22616 KB Output is correct
10 Correct 12 ms 22724 KB Output is correct
11 Correct 12 ms 22620 KB Output is correct
12 Correct 9 ms 22576 KB Output is correct
13 Correct 12 ms 22864 KB Output is correct
14 Correct 12 ms 22864 KB Output is correct
15 Correct 13 ms 22880 KB Output is correct
16 Correct 11 ms 22620 KB Output is correct
17 Correct 11 ms 22620 KB Output is correct
18 Correct 7 ms 22364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 575 ms 72456 KB Output is correct
2 Correct 576 ms 72264 KB Output is correct
3 Correct 563 ms 72696 KB Output is correct
4 Correct 360 ms 71948 KB Output is correct
5 Correct 481 ms 72264 KB Output is correct
6 Correct 172 ms 64580 KB Output is correct
7 Correct 542 ms 72516 KB Output is correct
8 Correct 532 ms 72520 KB Output is correct
9 Correct 534 ms 72308 KB Output is correct
10 Correct 368 ms 69324 KB Output is correct
11 Correct 252 ms 69480 KB Output is correct
12 Correct 126 ms 64124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 575 ms 72456 KB Output is correct
2 Correct 576 ms 72264 KB Output is correct
3 Correct 563 ms 72696 KB Output is correct
4 Correct 360 ms 71948 KB Output is correct
5 Correct 481 ms 72264 KB Output is correct
6 Correct 172 ms 64580 KB Output is correct
7 Correct 542 ms 72516 KB Output is correct
8 Correct 532 ms 72520 KB Output is correct
9 Correct 534 ms 72308 KB Output is correct
10 Correct 368 ms 69324 KB Output is correct
11 Correct 252 ms 69480 KB Output is correct
12 Correct 126 ms 64124 KB Output is correct
13 Correct 601 ms 72456 KB Output is correct
14 Correct 607 ms 75324 KB Output is correct
15 Correct 556 ms 74944 KB Output is correct
16 Correct 396 ms 74492 KB Output is correct
17 Correct 497 ms 74420 KB Output is correct
18 Correct 179 ms 65588 KB Output is correct
19 Correct 615 ms 75588 KB Output is correct
20 Correct 623 ms 75592 KB Output is correct
21 Correct 599 ms 75588 KB Output is correct
22 Correct 353 ms 71468 KB Output is correct
23 Correct 258 ms 71236 KB Output is correct
24 Correct 127 ms 65096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21336 KB Output is correct
2 Correct 4 ms 21340 KB Output is correct
3 Correct 4 ms 21340 KB Output is correct
4 Correct 4 ms 21280 KB Output is correct
5 Correct 4 ms 21340 KB Output is correct
6 Correct 5 ms 21340 KB Output is correct
7 Correct 13 ms 22620 KB Output is correct
8 Correct 13 ms 22620 KB Output is correct
9 Correct 12 ms 22616 KB Output is correct
10 Correct 12 ms 22724 KB Output is correct
11 Correct 12 ms 22620 KB Output is correct
12 Correct 9 ms 22576 KB Output is correct
13 Correct 12 ms 22864 KB Output is correct
14 Correct 12 ms 22864 KB Output is correct
15 Correct 13 ms 22880 KB Output is correct
16 Correct 11 ms 22620 KB Output is correct
17 Correct 11 ms 22620 KB Output is correct
18 Correct 7 ms 22364 KB Output is correct
19 Correct 575 ms 72456 KB Output is correct
20 Correct 576 ms 72264 KB Output is correct
21 Correct 563 ms 72696 KB Output is correct
22 Correct 360 ms 71948 KB Output is correct
23 Correct 481 ms 72264 KB Output is correct
24 Correct 172 ms 64580 KB Output is correct
25 Correct 542 ms 72516 KB Output is correct
26 Correct 532 ms 72520 KB Output is correct
27 Correct 534 ms 72308 KB Output is correct
28 Correct 368 ms 69324 KB Output is correct
29 Correct 252 ms 69480 KB Output is correct
30 Correct 126 ms 64124 KB Output is correct
31 Correct 601 ms 72456 KB Output is correct
32 Correct 607 ms 75324 KB Output is correct
33 Correct 556 ms 74944 KB Output is correct
34 Correct 396 ms 74492 KB Output is correct
35 Correct 497 ms 74420 KB Output is correct
36 Correct 179 ms 65588 KB Output is correct
37 Correct 615 ms 75588 KB Output is correct
38 Correct 623 ms 75592 KB Output is correct
39 Correct 599 ms 75588 KB Output is correct
40 Correct 353 ms 71468 KB Output is correct
41 Correct 258 ms 71236 KB Output is correct
42 Correct 127 ms 65096 KB Output is correct
43 Correct 617 ms 77336 KB Output is correct
44 Correct 617 ms 77384 KB Output is correct
45 Correct 596 ms 77124 KB Output is correct
46 Correct 411 ms 75936 KB Output is correct
47 Correct 503 ms 75892 KB Output is correct
48 Correct 179 ms 65492 KB Output is correct
49 Correct 598 ms 77184 KB Output is correct
50 Correct 583 ms 77092 KB Output is correct
51 Correct 584 ms 77212 KB Output is correct
52 Correct 415 ms 75592 KB Output is correct
53 Correct 286 ms 74768 KB Output is correct