Submission #103276

# Submission time Handle Problem Language Result Execution time Memory
103276 2019-03-29T12:41:10 Z pxh612 Examination (JOI19_examination) C++14
100 / 100
1152 ms 54732 KB
#include<bits/stdc++.h>
using namespace std;

#define in ({ll x=0;int n=0,c=getchar();for(;!isdigit(c);c=getchar()) n=c=='-';for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define inchar ({char c=getchar();while(c==' '||c=='\n') c=getchar();c;})
#define DO for(bool __=1;__;___=0)

#define ll long long
#define FOR(i,a,b) for(int i(a);i<=b;i++)
#define ROF(i,a,b) for(int i(b);a<=i;i--)
#define rr(x) " "<<#x<<'='<<x<<" "

#define bit(x,i) ((x>>(i-1))&1ll)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1ll<<(i-1)))
#define pow2(x) (1ll<<x)

#define mt make_tuple
#define pi pair<int,int>
#define x first
#define y second

#define VEC(i,a) for(auto&i:a)
#define pb push_back
#define allv(a) a.begin(),a.end()
#define endv(a) (int)a.size()-1
////////////////////////////////////////// NIRO
const int N=1e5+5;
int n,Q;

struct tp
{
    int a,b,c,id;
};
tp a[N],a2[N],q[N];
int don,ans[N],finda[N];

bool sortc(tp a,tp b){return a.c<b.c;}
bool sortab(tp u,tp v){return u.a<v.a||(u.a==v.a&&u.b<v.b);}



#define middle(a,b) (a+(b-a)/2)
#define Sfir 1,1,n
#define Snow S,l,r
#define Slef S*2,l,middle(l,r)
#define Srig S*2+1,middle(l,r)+1,r
int s[4*N];
vector<int> ffen[4*N],fen[4*N];
void BUI(int S,int l,int r)
{
   // cout<<rr(S) rr(l) rr(r) "\n";
    FOR(i,l,r) ffen[S].pb(a[i].b);
    sort(allv(ffen[S]));
    fen[S].resize(ffen[S].size(),0);

    //cout<<rr(S) ":";
    //VEC(i,ffen[S]) cout<<i<<" ";cout<<"\n";
    if(l==r) return;
    BUI(Slef);BUI(Srig);
}


void UPDFEN(int S,int v)
{
    //if(S==3&&v==70) cout<<"YES\n\n";
    int i=lower_bound(allv(ffen[S]),v)-ffen[S].begin()+1;
    for(;i>0;i-=i&-i) fen[S][i-1]++;
}
int GETFEN(int S,int v)
{
    int sum=0;
    int i=lower_bound(allv(ffen[S]),v)-ffen[S].begin()+1;
    for(;i<=fen[S].size();i+=i&-i) sum+=fen[S][i-1];
    //cout<<rr(S) rr(v) rr(i) rr(fen[S].size()) rr(sum) "\n";
    return sum;
}


void UPD(int S,int l,int r,int x)
{
    if(x<l||r<x) return;

    //if(S==1) cout<<"update" rr(S) rr(l) rr(r) rr(x) "\n";
    UPDFEN(S,a[x].b);
	if(l!=r)
        UPD(Slef,x),
        UPD(Srig,x);
}
int GET(int S,int l,int r,int u,int v,int z)
{
	if(v<l||r<u) return 0;

	if(u<=l&&r<=v) return GETFEN(S,z);
	return GET(Slef,u,v,z)+GET(Srig,u,v,z);
}

int FIND(int x)
{
    //cout<<"find" rr(x) " --> ";
    int l=1,r=n,res=0;

    while(l<=r)

    {
        int mid=l+(r-l)/2;
        if(x<=a[mid].a) res=mid,r=mid-1;
        else l=mid+1;
    }
    //cout<<rr(res) "\n";
    return res;
}

main()
{
    //freopen("nr.inp","r",stdin);
   // freopen("nr.out","w",stdout);
    n=in,Q=in;
    //cout<<rr(n) rr(Q) "\n";
    FOR(i,1,n)
    {
        int x=in,y=in;
        a[i]=a2[i]={x,y,x+y,i};
    }
    FOR(i,1,Q) q[i]={in,in,in,i};

    sort(a2+1,a2+n+1,sortc);
    sort(q+1,q+Q+1,sortc);
    sort(a+1,a+n+1,sortab);
    FOR(i,1,n) finda[a[i].id]=i;

    //FOR(i,1,n) cout<<rr(i) <<a[i].a<<" "<<a[i].b<<" "<<a[i].c<<"\n";
    //FOR(i,1,n) cout<<finda[i]<<" ";cout<<"\n";
    BUI(1,1,n);
    don=n;

    ROF(i,1,Q)
    {
        //cout<<"=======================" rr(i) rr(q[i].a) rr(q[i].b) rr(q[i].c) "\n";
        while(don>0&&q[i].c<=a2[don].c) UPD(Sfir,finda[a2[don].id]),don--;

        int findd=FIND(q[i].a);
        if(findd!=0) ans[q[i].id]=GET(Sfir,findd,n,q[i].b);
       // break;
    }
    FOR(i,1,Q) cout<<ans[i]<<"\n";
}

Compilation message

examination.cpp: In function 'int GETFEN(int, int)':
examination.cpp:74:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(;i<=fen[S].size();i+=i&-i) sum+=fen[S][i-1];
          ~^~~~~~~~~~~~~~~
examination.cpp: At global scope:
examination.cpp:114:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
examination.cpp: In function 'int main()':
examination.cpp:4:128: warning: narrowing conversion of '({...})' from 'long long int' to 'int' inside { } [-Wnarrowing]
 #define in ({ll x=0;int n=0,c=getchar();for(;!isdigit(c);c=getchar()) n=c=='-';for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
                                                                                                                                ^
examination.cpp:125:22: note: in expansion of macro 'in'
     FOR(i,1,Q) q[i]={in,in,in,i};
                      ^~
examination.cpp:4:128: warning: narrowing conversion of '({...})' from 'long long int' to 'int' inside { } [-Wnarrowing]
 #define in ({ll x=0;int n=0,c=getchar();for(;!isdigit(c);c=getchar()) n=c=='-';for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
                                                                                                                                ^
examination.cpp:125:25: note: in expansion of macro 'in'
     FOR(i,1,Q) q[i]={in,in,in,i};
                         ^~
examination.cpp:4:128: warning: narrowing conversion of '({...})' from 'long long int' to 'int' inside { } [-Wnarrowing]
 #define in ({ll x=0;int n=0,c=getchar();for(;!isdigit(c);c=getchar()) n=c=='-';for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
                                                                                                                                ^
examination.cpp:125:28: note: in expansion of macro 'in'
     FOR(i,1,Q) q[i]={in,in,in,i};
                            ^~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 19200 KB Output is correct
2 Correct 18 ms 19200 KB Output is correct
3 Correct 18 ms 19200 KB Output is correct
4 Correct 20 ms 19192 KB Output is correct
5 Correct 21 ms 19200 KB Output is correct
6 Correct 27 ms 19064 KB Output is correct
7 Correct 44 ms 20088 KB Output is correct
8 Correct 34 ms 20088 KB Output is correct
9 Correct 32 ms 20096 KB Output is correct
10 Correct 30 ms 19968 KB Output is correct
11 Correct 32 ms 20088 KB Output is correct
12 Correct 33 ms 19960 KB Output is correct
13 Correct 44 ms 20088 KB Output is correct
14 Correct 47 ms 20088 KB Output is correct
15 Correct 27 ms 20088 KB Output is correct
16 Correct 27 ms 20088 KB Output is correct
17 Correct 29 ms 20088 KB Output is correct
18 Correct 27 ms 20096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 919 ms 49648 KB Output is correct
2 Correct 839 ms 49904 KB Output is correct
3 Correct 1056 ms 52224 KB Output is correct
4 Correct 549 ms 51564 KB Output is correct
5 Correct 520 ms 51620 KB Output is correct
6 Correct 378 ms 50732 KB Output is correct
7 Correct 918 ms 52160 KB Output is correct
8 Correct 886 ms 52240 KB Output is correct
9 Correct 879 ms 52080 KB Output is correct
10 Correct 342 ms 51180 KB Output is correct
11 Correct 485 ms 51388 KB Output is correct
12 Correct 225 ms 50544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 919 ms 49648 KB Output is correct
2 Correct 839 ms 49904 KB Output is correct
3 Correct 1056 ms 52224 KB Output is correct
4 Correct 549 ms 51564 KB Output is correct
5 Correct 520 ms 51620 KB Output is correct
6 Correct 378 ms 50732 KB Output is correct
7 Correct 918 ms 52160 KB Output is correct
8 Correct 886 ms 52240 KB Output is correct
9 Correct 879 ms 52080 KB Output is correct
10 Correct 342 ms 51180 KB Output is correct
11 Correct 485 ms 51388 KB Output is correct
12 Correct 225 ms 50544 KB Output is correct
13 Correct 1119 ms 52580 KB Output is correct
14 Correct 1060 ms 52720 KB Output is correct
15 Correct 942 ms 52204 KB Output is correct
16 Correct 654 ms 51872 KB Output is correct
17 Correct 593 ms 51692 KB Output is correct
18 Correct 389 ms 50796 KB Output is correct
19 Correct 1025 ms 52592 KB Output is correct
20 Correct 1136 ms 52672 KB Output is correct
21 Correct 903 ms 52704 KB Output is correct
22 Correct 400 ms 51312 KB Output is correct
23 Correct 403 ms 51424 KB Output is correct
24 Correct 260 ms 50416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 19200 KB Output is correct
2 Correct 18 ms 19200 KB Output is correct
3 Correct 18 ms 19200 KB Output is correct
4 Correct 20 ms 19192 KB Output is correct
5 Correct 21 ms 19200 KB Output is correct
6 Correct 27 ms 19064 KB Output is correct
7 Correct 44 ms 20088 KB Output is correct
8 Correct 34 ms 20088 KB Output is correct
9 Correct 32 ms 20096 KB Output is correct
10 Correct 30 ms 19968 KB Output is correct
11 Correct 32 ms 20088 KB Output is correct
12 Correct 33 ms 19960 KB Output is correct
13 Correct 44 ms 20088 KB Output is correct
14 Correct 47 ms 20088 KB Output is correct
15 Correct 27 ms 20088 KB Output is correct
16 Correct 27 ms 20088 KB Output is correct
17 Correct 29 ms 20088 KB Output is correct
18 Correct 27 ms 20096 KB Output is correct
19 Correct 919 ms 49648 KB Output is correct
20 Correct 839 ms 49904 KB Output is correct
21 Correct 1056 ms 52224 KB Output is correct
22 Correct 549 ms 51564 KB Output is correct
23 Correct 520 ms 51620 KB Output is correct
24 Correct 378 ms 50732 KB Output is correct
25 Correct 918 ms 52160 KB Output is correct
26 Correct 886 ms 52240 KB Output is correct
27 Correct 879 ms 52080 KB Output is correct
28 Correct 342 ms 51180 KB Output is correct
29 Correct 485 ms 51388 KB Output is correct
30 Correct 225 ms 50544 KB Output is correct
31 Correct 1119 ms 52580 KB Output is correct
32 Correct 1060 ms 52720 KB Output is correct
33 Correct 942 ms 52204 KB Output is correct
34 Correct 654 ms 51872 KB Output is correct
35 Correct 593 ms 51692 KB Output is correct
36 Correct 389 ms 50796 KB Output is correct
37 Correct 1025 ms 52592 KB Output is correct
38 Correct 1136 ms 52672 KB Output is correct
39 Correct 903 ms 52704 KB Output is correct
40 Correct 400 ms 51312 KB Output is correct
41 Correct 403 ms 51424 KB Output is correct
42 Correct 260 ms 50416 KB Output is correct
43 Correct 1101 ms 54584 KB Output is correct
44 Correct 1152 ms 54648 KB Output is correct
45 Correct 981 ms 54732 KB Output is correct
46 Correct 565 ms 53076 KB Output is correct
47 Correct 544 ms 52972 KB Output is correct
48 Correct 357 ms 50616 KB Output is correct
49 Correct 1059 ms 54508 KB Output is correct
50 Correct 1094 ms 54424 KB Output is correct
51 Correct 907 ms 54416 KB Output is correct
52 Correct 345 ms 52808 KB Output is correct
53 Correct 385 ms 52048 KB Output is correct