Submission #345566

# Submission time Handle Problem Language Result Execution time Memory
345566 2021-01-07T14:58:10 Z Kerim Examination (JOI19_examination) C++17
100 / 100
1787 ms 14752 KB
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int a[MAXN],b[MAXN],c[MAXN],id[MAXN];
int x[MAXN],y[MAXN],z[MAXN],di[MAXN];
vector<int>v;
int en[MAXN],bel[MAXN],cur,sz[MAXN],n,q;
bool cmp(int xx,int yy){
	return (a[xx]>a[yy]);	
}
bool cmp1(int xx,int yy){
	return (x[xx]>x[yy]);	
}
int who(int x){
	return (lower_bound(all(v),x)-v.begin())+1;
}
void init(){
	int BLOK=sqrt(n);cur=1;
	for(int i=1;i<=n;i++){
		bel[i]=cur;
		if(i%BLOK==0){
			if(i==n)
				en[cur]=i;
			else
				en[cur++]=i;
		}
	}en[cur]=n;
}
vector<int>adj[MAXN];
int arr[MAXN],ans[MAXN];
void upd(int p,int v){
	arr[p]=v;
	adj[bel[p]].pb(v);sz[bel[p]]++;
	sort(all(adj[bel[p]]));
}
int get(int p,int v){
	if(p<1 or p>n)return 0;
	int ans=0;
	for(int i=p;i<=en[bel[p]];i++)
		ans+=(arr[i]>=v);
	for(int i=bel[p]+1;i<=cur;i++)
		if(!adj[i].empty())
			ans+=sz[i]-int(lower_bound(all(adj[i]),v)-adj[i].begin());
	return ans;
}
int can[MAXN];
int main(){
	memset(arr,-1,sizeof arr);
   // freopen("file.in", "r", stdin);
    scanf("%d%d",&n,&q);
    vector<PII>g;
    for(int i=1;i<=n;i++){
    	scanf("%d%d",a+i,b+i);
    	c[i]=a[i]+b[i];
    	id[i]=i;
		v.pb(b[i]);
		g.pb(mp(b[i],i));
    }
    sort(all(v));sort(all(g));
    for(int i=0;i<n;i++)
    	can[g[i].ss]=i+1;
    init();
    sort(id+1,id+n+1,cmp);
    for(int i=1;i<=q;i++)
    	scanf("%d%d%d",x+i,y+i,z+i),di[i]=i;
    sort(di+1,di+q+1,cmp1);
    int p=1;
    for(int i=1;i<=q;i++){
    	while(p<=n and a[id[p]]>=x[di[i]])
    		upd(can[id[p]],c[id[p]]),p++;
    	ans[di[i]]=get(who(y[di[i]]),z[di[i]]);
    }
    for(int i=1;i<=q;i++)
    	printf("%d\n",ans[i]);
	return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:89:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   89 |     for(int i=1;i<=q;i++)
      |     ^~~
examination.cpp:91:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   91 |  return 0;
      |  ^~~~~~
examination.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   66 |     scanf("%d%d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~
examination.cpp:69:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   69 |      scanf("%d%d",a+i,b+i);
      |      ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:81:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   81 |      scanf("%d%d%d",x+i,y+i,z+i),di[i]=i;
      |      ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3180 KB Output is correct
2 Correct 2 ms 3180 KB Output is correct
3 Correct 3 ms 3180 KB Output is correct
4 Correct 2 ms 3180 KB Output is correct
5 Correct 2 ms 3180 KB Output is correct
6 Correct 3 ms 3180 KB Output is correct
7 Correct 9 ms 3308 KB Output is correct
8 Correct 9 ms 3308 KB Output is correct
9 Correct 9 ms 3308 KB Output is correct
10 Correct 10 ms 3308 KB Output is correct
11 Correct 11 ms 3308 KB Output is correct
12 Correct 9 ms 3308 KB Output is correct
13 Correct 10 ms 3312 KB Output is correct
14 Correct 8 ms 3308 KB Output is correct
15 Correct 8 ms 3308 KB Output is correct
16 Correct 6 ms 3308 KB Output is correct
17 Correct 9 ms 3308 KB Output is correct
18 Correct 5 ms 3308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1058 ms 9876 KB Output is correct
2 Correct 926 ms 9984 KB Output is correct
3 Correct 1002 ms 9876 KB Output is correct
4 Correct 965 ms 9888 KB Output is correct
5 Correct 808 ms 11664 KB Output is correct
6 Correct 800 ms 10932 KB Output is correct
7 Correct 951 ms 12316 KB Output is correct
8 Correct 1178 ms 12312 KB Output is correct
9 Correct 1288 ms 12204 KB Output is correct
10 Correct 659 ms 11476 KB Output is correct
11 Correct 880 ms 11484 KB Output is correct
12 Correct 227 ms 10460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1058 ms 9876 KB Output is correct
2 Correct 926 ms 9984 KB Output is correct
3 Correct 1002 ms 9876 KB Output is correct
4 Correct 965 ms 9888 KB Output is correct
5 Correct 808 ms 11664 KB Output is correct
6 Correct 800 ms 10932 KB Output is correct
7 Correct 951 ms 12316 KB Output is correct
8 Correct 1178 ms 12312 KB Output is correct
9 Correct 1288 ms 12204 KB Output is correct
10 Correct 659 ms 11476 KB Output is correct
11 Correct 880 ms 11484 KB Output is correct
12 Correct 227 ms 10460 KB Output is correct
13 Correct 1148 ms 12764 KB Output is correct
14 Correct 1026 ms 12796 KB Output is correct
15 Correct 941 ms 12380 KB Output is correct
16 Correct 1199 ms 12048 KB Output is correct
17 Correct 727 ms 12060 KB Output is correct
18 Correct 783 ms 10972 KB Output is correct
19 Correct 1096 ms 12840 KB Output is correct
20 Correct 1101 ms 12812 KB Output is correct
21 Correct 1451 ms 12764 KB Output is correct
22 Correct 678 ms 11468 KB Output is correct
23 Correct 867 ms 11616 KB Output is correct
24 Correct 212 ms 10460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3180 KB Output is correct
2 Correct 2 ms 3180 KB Output is correct
3 Correct 3 ms 3180 KB Output is correct
4 Correct 2 ms 3180 KB Output is correct
5 Correct 2 ms 3180 KB Output is correct
6 Correct 3 ms 3180 KB Output is correct
7 Correct 9 ms 3308 KB Output is correct
8 Correct 9 ms 3308 KB Output is correct
9 Correct 9 ms 3308 KB Output is correct
10 Correct 10 ms 3308 KB Output is correct
11 Correct 11 ms 3308 KB Output is correct
12 Correct 9 ms 3308 KB Output is correct
13 Correct 10 ms 3312 KB Output is correct
14 Correct 8 ms 3308 KB Output is correct
15 Correct 8 ms 3308 KB Output is correct
16 Correct 6 ms 3308 KB Output is correct
17 Correct 9 ms 3308 KB Output is correct
18 Correct 5 ms 3308 KB Output is correct
19 Correct 1058 ms 9876 KB Output is correct
20 Correct 926 ms 9984 KB Output is correct
21 Correct 1002 ms 9876 KB Output is correct
22 Correct 965 ms 9888 KB Output is correct
23 Correct 808 ms 11664 KB Output is correct
24 Correct 800 ms 10932 KB Output is correct
25 Correct 951 ms 12316 KB Output is correct
26 Correct 1178 ms 12312 KB Output is correct
27 Correct 1288 ms 12204 KB Output is correct
28 Correct 659 ms 11476 KB Output is correct
29 Correct 880 ms 11484 KB Output is correct
30 Correct 227 ms 10460 KB Output is correct
31 Correct 1148 ms 12764 KB Output is correct
32 Correct 1026 ms 12796 KB Output is correct
33 Correct 941 ms 12380 KB Output is correct
34 Correct 1199 ms 12048 KB Output is correct
35 Correct 727 ms 12060 KB Output is correct
36 Correct 783 ms 10972 KB Output is correct
37 Correct 1096 ms 12840 KB Output is correct
38 Correct 1101 ms 12812 KB Output is correct
39 Correct 1451 ms 12764 KB Output is correct
40 Correct 678 ms 11468 KB Output is correct
41 Correct 867 ms 11616 KB Output is correct
42 Correct 212 ms 10460 KB Output is correct
43 Correct 1125 ms 14752 KB Output is correct
44 Correct 1055 ms 14716 KB Output is correct
45 Correct 1049 ms 14684 KB Output is correct
46 Correct 1224 ms 13308 KB Output is correct
47 Correct 693 ms 13224 KB Output is correct
48 Correct 803 ms 10776 KB Output is correct
49 Correct 1234 ms 14604 KB Output is correct
50 Correct 1494 ms 14728 KB Output is correct
51 Correct 1787 ms 14556 KB Output is correct
52 Correct 625 ms 13020 KB Output is correct
53 Correct 950 ms 12256 KB Output is correct