Submission #103524

# Submission time Handle Problem Language Result Execution time Memory
103524 2019-03-31T05:30:36 Z tduong0806 Examination (JOI19_examination) C++14
100 / 100
821 ms 27248 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define forv(a,b) for(auto &a:b)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define reset(f,x) memset(f,x,sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define onbit(x,i) (x|(1<<(i-1)))
#define offbit(x,i) (x&~(1<<(i-1)))
#define read2(a,b) read(a),read(b)
#define read3(a,b,c) read(a),read(b),read(c)
const int N=100010;
int n,m,ans[N];
vector<int> t[N],e,sv[N];
struct oo {int x,y,z,id;} a[N],q[N];
bool cmp(oo u,oo v) {return u.x>v.x;}
int v(int x) {return lower_bound(all(e),x)-e.begin()+1;}
int vz(int i,int x) {return lower_bound(all(sv[i]),x)-sv[i].begin()+1;}
void add(int i,int j)
{
    i=v(i);
    for(;i;i-=i&-i) t[i].pb(0),sv[i].pb(j);
}
void update(int i,int j)
{
    i=v(i);
    for(;i;i-=i&-i)
    {
        int _j=vz(i,j);
        for(;_j;_j-=_j&-_j) t[i][_j]++;
    }
}
int get(int i,int j)
{
    int g=0;
    i=v(i);
    for(;i<=n;i+=i&-i)
    {
        int _j=vz(i,j);
        for(;_j<t[i].size();_j+=_j&-_j) g+=t[i][_j];
    }
    return g;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("Examination.inp","r",stdin);
    cin>>n>>m;
    forinc(i,1,n)
    {
        cin>>a[i].x>>a[i].y,a[i].z=a[i].x+a[i].y;
        e.pb(a[i].y);
    }
    sort(all(e));
    forinc(i,1,m)
    {
        cin>>q[i].x>>q[i].y>>q[i].z;
        q[i].id=i;
    }
    forinc(i,1,n)
    {
        t[i].pb(0);
        add(a[i].y,a[i].z);
    }
    forinc(i,1,n) sort(all(sv[i]));
    sort(a+1,a+n+1,cmp);
    sort(q+1,q+m+1,cmp);
    int top=1;
    forinc(i,1,m)
    {
        while(top<=n&&a[top].x>=q[i].x) update(a[top].y,a[top].z),top++;
        ans[q[i].id]=get(q[i].y,q[i].z);
    }
    forinc(i,1,m) cout<<ans[i]<<"\n";
}

Compilation message

examination.cpp: In function 'int get(int, int)':
examination.cpp:47:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(;_j<t[i].size();_j+=_j&-_j) g+=t[i][_j];
              ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 8 ms 5120 KB Output is correct
3 Correct 2 ms 5092 KB Output is correct
4 Correct 6 ms 4992 KB Output is correct
5 Correct 6 ms 4992 KB Output is correct
6 Correct 8 ms 4992 KB Output is correct
7 Correct 18 ms 5632 KB Output is correct
8 Correct 15 ms 5632 KB Output is correct
9 Correct 15 ms 5632 KB Output is correct
10 Correct 14 ms 5504 KB Output is correct
11 Correct 15 ms 5632 KB Output is correct
12 Correct 12 ms 5504 KB Output is correct
13 Correct 19 ms 5632 KB Output is correct
14 Correct 18 ms 5632 KB Output is correct
15 Correct 15 ms 5632 KB Output is correct
16 Correct 15 ms 5680 KB Output is correct
17 Correct 12 ms 5376 KB Output is correct
18 Correct 9 ms 5376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 719 ms 25004 KB Output is correct
2 Correct 685 ms 25124 KB Output is correct
3 Correct 571 ms 24820 KB Output is correct
4 Correct 224 ms 23256 KB Output is correct
5 Correct 625 ms 24352 KB Output is correct
6 Correct 178 ms 22516 KB Output is correct
7 Correct 630 ms 24772 KB Output is correct
8 Correct 602 ms 24876 KB Output is correct
9 Correct 606 ms 24788 KB Output is correct
10 Correct 600 ms 24112 KB Output is correct
11 Correct 107 ms 15144 KB Output is correct
12 Correct 77 ms 14044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 719 ms 25004 KB Output is correct
2 Correct 685 ms 25124 KB Output is correct
3 Correct 571 ms 24820 KB Output is correct
4 Correct 224 ms 23256 KB Output is correct
5 Correct 625 ms 24352 KB Output is correct
6 Correct 178 ms 22516 KB Output is correct
7 Correct 630 ms 24772 KB Output is correct
8 Correct 602 ms 24876 KB Output is correct
9 Correct 606 ms 24788 KB Output is correct
10 Correct 600 ms 24112 KB Output is correct
11 Correct 107 ms 15144 KB Output is correct
12 Correct 77 ms 14044 KB Output is correct
13 Correct 707 ms 25352 KB Output is correct
14 Correct 688 ms 25480 KB Output is correct
15 Correct 655 ms 25288 KB Output is correct
16 Correct 277 ms 23284 KB Output is correct
17 Correct 683 ms 24564 KB Output is correct
18 Correct 227 ms 22388 KB Output is correct
19 Correct 655 ms 25568 KB Output is correct
20 Correct 731 ms 25528 KB Output is correct
21 Correct 638 ms 25396 KB Output is correct
22 Correct 671 ms 24068 KB Output is correct
23 Correct 117 ms 14836 KB Output is correct
24 Correct 81 ms 14068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 8 ms 5120 KB Output is correct
3 Correct 2 ms 5092 KB Output is correct
4 Correct 6 ms 4992 KB Output is correct
5 Correct 6 ms 4992 KB Output is correct
6 Correct 8 ms 4992 KB Output is correct
7 Correct 18 ms 5632 KB Output is correct
8 Correct 15 ms 5632 KB Output is correct
9 Correct 15 ms 5632 KB Output is correct
10 Correct 14 ms 5504 KB Output is correct
11 Correct 15 ms 5632 KB Output is correct
12 Correct 12 ms 5504 KB Output is correct
13 Correct 19 ms 5632 KB Output is correct
14 Correct 18 ms 5632 KB Output is correct
15 Correct 15 ms 5632 KB Output is correct
16 Correct 15 ms 5680 KB Output is correct
17 Correct 12 ms 5376 KB Output is correct
18 Correct 9 ms 5376 KB Output is correct
19 Correct 719 ms 25004 KB Output is correct
20 Correct 685 ms 25124 KB Output is correct
21 Correct 571 ms 24820 KB Output is correct
22 Correct 224 ms 23256 KB Output is correct
23 Correct 625 ms 24352 KB Output is correct
24 Correct 178 ms 22516 KB Output is correct
25 Correct 630 ms 24772 KB Output is correct
26 Correct 602 ms 24876 KB Output is correct
27 Correct 606 ms 24788 KB Output is correct
28 Correct 600 ms 24112 KB Output is correct
29 Correct 107 ms 15144 KB Output is correct
30 Correct 77 ms 14044 KB Output is correct
31 Correct 707 ms 25352 KB Output is correct
32 Correct 688 ms 25480 KB Output is correct
33 Correct 655 ms 25288 KB Output is correct
34 Correct 277 ms 23284 KB Output is correct
35 Correct 683 ms 24564 KB Output is correct
36 Correct 227 ms 22388 KB Output is correct
37 Correct 655 ms 25568 KB Output is correct
38 Correct 731 ms 25528 KB Output is correct
39 Correct 638 ms 25396 KB Output is correct
40 Correct 671 ms 24068 KB Output is correct
41 Correct 117 ms 14836 KB Output is correct
42 Correct 81 ms 14068 KB Output is correct
43 Correct 804 ms 27200 KB Output is correct
44 Correct 821 ms 27164 KB Output is correct
45 Correct 798 ms 27040 KB Output is correct
46 Correct 340 ms 25332 KB Output is correct
47 Correct 760 ms 26388 KB Output is correct
48 Correct 173 ms 22512 KB Output is correct
49 Correct 698 ms 27248 KB Output is correct
50 Correct 719 ms 27164 KB Output is correct
51 Correct 695 ms 27124 KB Output is correct
52 Correct 699 ms 26228 KB Output is correct
53 Correct 118 ms 15732 KB Output is correct