Submission #1083195

# Submission time Handle Problem Language Result Execution time Memory
1083195 2024-09-02T17:50:29 Z StefanSebez Examination (JOI19_examination) C++14
100 / 100
492 ms 32240 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
const int N=1e5+50;
struct Query{
    int x,y,z,i;
    bool operator <(Query a){return z<a.z;}
}Qs[N+50];
vector<int>T[N+50],vals[N+50];
pair<int,int>a[N+50];
int res[N+50];
void update(int qind,int qind1,int qval){
    int lb=lower_bound(vals[qind].begin(),vals[qind].end(),qind1)-vals[qind].begin();
    //if(lb==0) return;
    for(int i=lb;i<T[qind].size();i+=i&-i) T[qind][i]+=qval;
}
void Update(int qind,int qind1,int qval,bool precalc){
    if(precalc) for(int i=qind;i<=N;i+=i&-i) vals[i].pb(qind1);
    else for(int i=qind;i<=N;i+=i&-i) update(i,qind1,qval);
}
int get(int qind,int qval){
    int sum=0;
    for(int i=T[qind].size()-1;i>=1;i-=i&-i) sum+=T[qind][i];
    int lb=lower_bound(vals[qind].begin(),vals[qind].end(),qval)-vals[qind].begin()-1;
    for(int i=lb;i>=1;i-=i&-i) sum-=T[qind][i];
    return sum;
}
int Get(int qind,int qval){
    int sum=0;
	for(int i=qind;i>=1;i-=i&-i) sum+=get(i,qval);
    return sum;
}
vector<int>Vals;
int Ind(int x){
    return upper_bound(Vals.begin(),Vals.end(),x)-Vals.begin()-1;
}
int main(){
    int n,q;scanf("%i%i",&n,&q);
    for(int i=1;i<=n;i++) scanf("%i%i",&a[i].fi,&a[i].se);
    Vals.pb(-1);
    for(int i=1;i<=n;i++) Vals.pb(a[i].fi);
    sort(Vals.begin(),Vals.end());
    int M=unique(Vals.begin(),Vals.end())-Vals.begin();
    Vals.resize(M);
    //for(auto i:Vals) printf("%i ",i);printf("\n");
    for(int i=1;i<=n;i++) Update(Ind(a[i].fi),a[i].se,1,true);
    for(int i=0;i<=N;i++){
		//printf("%i: ",i);for(auto j:vals[i]) printf("%i ",j);printf("\n");
        vals[i].pb(-1);
        sort(vals[i].begin(),vals[i].end());
        int m=unique(vals[i].begin(),vals[i].end())-vals[i].begin();
        vals[i].resize(m);
        for(int j=0;j<m;j++) T[i].pb(0);
        //printf("%i: ",i);for(auto j:vals[i]) printf("%i ",j);printf("\n");
    }
    for(int i=1;i<=n;i++) Update(Ind(a[i].fi),a[i].se,1,false);
    sort(a+1,a+n+1,[&](pair<int,int> i,pair<int,int> j){return i.fi+i.se<j.fi+j.se;});
    for(int i=1;i<=q;i++){
        int x,y,z;scanf("%i%i%i",&x,&y,&z);
        Qs[i]={x,y,z,i};
    }
    sort(Qs+1,Qs+q+1);
    //for(int i=1;i<=n;i++) printf("%i %i\n",a[i].fi,a[i].se);
    //for(int i=1;i<=q;i++) printf("%i %i %i\n",Qs[i].x,Qs[i].y,Qs[i].z);
    for(int i=1,j=1;j<=q;j++){
        while(i<=n && a[i].fi+a[i].se<Qs[j].z){
            Update(Ind(a[i].fi),a[i].se,-1,false);
            i++;
        }
        res[Qs[j].i]=Get(N,Qs[j].y)-Get(Ind(Qs[j].x-1),Qs[j].y);
        //printf("*%i %i %i %i %i %i\n",Ind(Qs[j].x-1),Qs[j].x,Qs[j].y,Qs[j].z,Get(N,Qs[j].y),Get(Ind(Qs[j].x-1),Qs[j].y));
    }
    for(int i=1;i<=q;i++) printf("%i ",res[i]);
    return 0;
}

Compilation message

examination.cpp: In function 'void update(int, int, int)':
examination.cpp:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i=lb;i<T[qind].size();i+=i&-i) T[qind][i]+=qval;
      |                  ~^~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:42:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     int n,q;scanf("%i%i",&n,&q);
      |             ~~~~~^~~~~~~~~~~~~~
examination.cpp:43:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     for(int i=1;i<=n;i++) scanf("%i%i",&a[i].fi,&a[i].se);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:63:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         int x,y,z;scanf("%i%i%i",&x,&y,&z);
      |                   ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 11356 KB Output is correct
2 Correct 11 ms 11356 KB Output is correct
3 Correct 9 ms 11356 KB Output is correct
4 Correct 10 ms 11296 KB Output is correct
5 Correct 10 ms 11272 KB Output is correct
6 Correct 10 ms 11356 KB Output is correct
7 Correct 19 ms 11868 KB Output is correct
8 Correct 19 ms 11864 KB Output is correct
9 Correct 25 ms 11868 KB Output is correct
10 Correct 15 ms 11784 KB Output is correct
11 Correct 18 ms 12124 KB Output is correct
12 Correct 13 ms 11612 KB Output is correct
13 Correct 18 ms 11864 KB Output is correct
14 Correct 22 ms 11824 KB Output is correct
15 Correct 18 ms 11864 KB Output is correct
16 Correct 16 ms 12124 KB Output is correct
17 Correct 15 ms 11612 KB Output is correct
18 Correct 12 ms 11736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 357 ms 24572 KB Output is correct
2 Correct 375 ms 24772 KB Output is correct
3 Correct 354 ms 24516 KB Output is correct
4 Correct 169 ms 20896 KB Output is correct
5 Correct 307 ms 28364 KB Output is correct
6 Correct 111 ms 23356 KB Output is correct
7 Correct 301 ms 24700 KB Output is correct
8 Correct 312 ms 24648 KB Output is correct
9 Correct 334 ms 24480 KB Output is correct
10 Correct 285 ms 28208 KB Output is correct
11 Correct 138 ms 20348 KB Output is correct
12 Correct 85 ms 23040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 357 ms 24572 KB Output is correct
2 Correct 375 ms 24772 KB Output is correct
3 Correct 354 ms 24516 KB Output is correct
4 Correct 169 ms 20896 KB Output is correct
5 Correct 307 ms 28364 KB Output is correct
6 Correct 111 ms 23356 KB Output is correct
7 Correct 301 ms 24700 KB Output is correct
8 Correct 312 ms 24648 KB Output is correct
9 Correct 334 ms 24480 KB Output is correct
10 Correct 285 ms 28208 KB Output is correct
11 Correct 138 ms 20348 KB Output is correct
12 Correct 85 ms 23040 KB Output is correct
13 Correct 474 ms 25136 KB Output is correct
14 Correct 424 ms 25076 KB Output is correct
15 Correct 359 ms 24776 KB Output is correct
16 Correct 204 ms 21288 KB Output is correct
17 Correct 380 ms 28872 KB Output is correct
18 Correct 119 ms 23240 KB Output is correct
19 Correct 459 ms 25100 KB Output is correct
20 Correct 459 ms 25036 KB Output is correct
21 Correct 463 ms 25032 KB Output is correct
22 Correct 283 ms 28332 KB Output is correct
23 Correct 137 ms 20200 KB Output is correct
24 Correct 90 ms 23224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 11356 KB Output is correct
2 Correct 11 ms 11356 KB Output is correct
3 Correct 9 ms 11356 KB Output is correct
4 Correct 10 ms 11296 KB Output is correct
5 Correct 10 ms 11272 KB Output is correct
6 Correct 10 ms 11356 KB Output is correct
7 Correct 19 ms 11868 KB Output is correct
8 Correct 19 ms 11864 KB Output is correct
9 Correct 25 ms 11868 KB Output is correct
10 Correct 15 ms 11784 KB Output is correct
11 Correct 18 ms 12124 KB Output is correct
12 Correct 13 ms 11612 KB Output is correct
13 Correct 18 ms 11864 KB Output is correct
14 Correct 22 ms 11824 KB Output is correct
15 Correct 18 ms 11864 KB Output is correct
16 Correct 16 ms 12124 KB Output is correct
17 Correct 15 ms 11612 KB Output is correct
18 Correct 12 ms 11736 KB Output is correct
19 Correct 357 ms 24572 KB Output is correct
20 Correct 375 ms 24772 KB Output is correct
21 Correct 354 ms 24516 KB Output is correct
22 Correct 169 ms 20896 KB Output is correct
23 Correct 307 ms 28364 KB Output is correct
24 Correct 111 ms 23356 KB Output is correct
25 Correct 301 ms 24700 KB Output is correct
26 Correct 312 ms 24648 KB Output is correct
27 Correct 334 ms 24480 KB Output is correct
28 Correct 285 ms 28208 KB Output is correct
29 Correct 138 ms 20348 KB Output is correct
30 Correct 85 ms 23040 KB Output is correct
31 Correct 474 ms 25136 KB Output is correct
32 Correct 424 ms 25076 KB Output is correct
33 Correct 359 ms 24776 KB Output is correct
34 Correct 204 ms 21288 KB Output is correct
35 Correct 380 ms 28872 KB Output is correct
36 Correct 119 ms 23240 KB Output is correct
37 Correct 459 ms 25100 KB Output is correct
38 Correct 459 ms 25036 KB Output is correct
39 Correct 463 ms 25032 KB Output is correct
40 Correct 283 ms 28332 KB Output is correct
41 Correct 137 ms 20200 KB Output is correct
42 Correct 90 ms 23224 KB Output is correct
43 Correct 470 ms 29404 KB Output is correct
44 Correct 492 ms 29428 KB Output is correct
45 Correct 431 ms 29516 KB Output is correct
46 Correct 219 ms 23548 KB Output is correct
47 Correct 382 ms 31824 KB Output is correct
48 Correct 148 ms 23088 KB Output is correct
49 Correct 391 ms 29324 KB Output is correct
50 Correct 446 ms 29368 KB Output is correct
51 Correct 353 ms 29256 KB Output is correct
52 Correct 369 ms 32240 KB Output is correct
53 Correct 140 ms 22220 KB Output is correct