답안 #402906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
402906 2021-05-12T13:33:07 Z keta_tsimakuridze Examination (JOI19_examination) C++14
100 / 100
2420 ms 213596 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional>
#define f first
#define s second
#define int long long
#define pii pair<int,int> 
using namespace __gnu_pbds; 
using namespace std;
const int N=2e5+5,mod=1e9+7;
int t,n,Q,ans[N];
pair<int,int>p[N];
vector<int> x;
pair<pair<int,int>,pair<int,int> >q[N];
map<int,int>ind;

 
typedef tree<pii, null_type, less<pii>, rb_tree_tag,  
            tree_order_statistics_node_update>  
    ordered_set;  
  ordered_set s[4*N];

void update(int u,int ind,int l,int r,int val,int idx){
	if(l>ind || r<ind) return;
	if(l==r) {
		s[u].insert({val,idx});
		return;
	}
	s[u].insert({val,idx});
	int mid=(l+r)/2;
	update(2*u,ind,l,mid,val,idx);
	update(2*u+1,ind,mid+1,r,val,idx);
}
int getans(int u,int start,int end,int l,int r,int val){
	if(l>end || r<start) return 0;
	if(start<=l&& r<=end) {
		return s[u].size() - s[u].order_of_key({val,0});
	}
	int mid=(l+r)/2;
	return getans(2*u,start,end,l,mid,val)+getans(2*u+1,start,end,mid+1,r,val);
}
 main(){
 	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	// t=1;
	cin>>n>>Q;
	for(int i=1;i<=n;i++){
		cin>>p[i].f>>p[i].s;
		x.push_back(p[i].s);
	}
	for(int i=1;i<=Q;i++){
		cin>>q[i].f.f>>q[i].f.s>>q[i].s.f;
		q[i].s.s=i;
		x.push_back(q[i].f.s);
	}
	sort(x.begin(),x.end());
	int idx=0;
	for(int i=0;i<x.size();i++){
		if(!i || x[i]!=x[i-1]) idx++;
		ind[x[i]] = idx;
	}
	sort(q+1,q+Q+1);
	sort(p+1,p+n+1);
	reverse(q+1,q+Q+1);
	reverse(p+1,p+n+1);
	int L=0;
	for(int i=1;i<=Q;i++){
		while(L<n && p[L+1].f>=q[i].f.f) L++,update(1,ind[p[L].s],1,idx,p[L].f+p[L].s,L);
		ans[q[i].s.s] = getans(1,ind[q[i].f.s],idx,1,idx,q[i].s.f);
	}
	for(int i=1;i<=Q;i++) cout<<ans[i]<<" ";
}

Compilation message

examination.cpp:43:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 |  main(){
      |  ^~~~
examination.cpp: In function 'int main()':
examination.cpp:58:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for(int i=0;i<x.size();i++){
      |              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 75456 KB Output is correct
2 Correct 67 ms 75468 KB Output is correct
3 Correct 73 ms 75476 KB Output is correct
4 Correct 68 ms 75392 KB Output is correct
5 Correct 67 ms 75420 KB Output is correct
6 Correct 67 ms 75444 KB Output is correct
7 Correct 111 ms 78636 KB Output is correct
8 Correct 99 ms 78644 KB Output is correct
9 Correct 99 ms 78516 KB Output is correct
10 Correct 92 ms 76524 KB Output is correct
11 Correct 97 ms 78660 KB Output is correct
12 Correct 100 ms 76528 KB Output is correct
13 Correct 99 ms 78700 KB Output is correct
14 Correct 97 ms 78784 KB Output is correct
15 Correct 108 ms 78648 KB Output is correct
16 Correct 97 ms 78612 KB Output is correct
17 Correct 84 ms 76112 KB Output is correct
18 Correct 84 ms 76388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2021 ms 197896 KB Output is correct
2 Correct 2051 ms 197976 KB Output is correct
3 Correct 2077 ms 197936 KB Output is correct
4 Correct 435 ms 111604 KB Output is correct
5 Correct 1082 ms 198820 KB Output is correct
6 Correct 356 ms 112384 KB Output is correct
7 Correct 2208 ms 198856 KB Output is correct
8 Correct 2028 ms 194812 KB Output is correct
9 Correct 1775 ms 194852 KB Output is correct
10 Correct 942 ms 198688 KB Output is correct
11 Correct 229 ms 96412 KB Output is correct
12 Correct 367 ms 102420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2021 ms 197896 KB Output is correct
2 Correct 2051 ms 197976 KB Output is correct
3 Correct 2077 ms 197936 KB Output is correct
4 Correct 435 ms 111604 KB Output is correct
5 Correct 1082 ms 198820 KB Output is correct
6 Correct 356 ms 112384 KB Output is correct
7 Correct 2208 ms 198856 KB Output is correct
8 Correct 2028 ms 194812 KB Output is correct
9 Correct 1775 ms 194852 KB Output is correct
10 Correct 942 ms 198688 KB Output is correct
11 Correct 229 ms 96412 KB Output is correct
12 Correct 367 ms 102420 KB Output is correct
13 Correct 2185 ms 198828 KB Output is correct
14 Correct 2094 ms 198936 KB Output is correct
15 Correct 2020 ms 198836 KB Output is correct
16 Correct 521 ms 112396 KB Output is correct
17 Correct 1116 ms 198924 KB Output is correct
18 Correct 368 ms 112392 KB Output is correct
19 Correct 2252 ms 198936 KB Output is correct
20 Correct 2307 ms 198852 KB Output is correct
21 Correct 2399 ms 197520 KB Output is correct
22 Correct 918 ms 198836 KB Output is correct
23 Correct 236 ms 96348 KB Output is correct
24 Correct 354 ms 102492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 75456 KB Output is correct
2 Correct 67 ms 75468 KB Output is correct
3 Correct 73 ms 75476 KB Output is correct
4 Correct 68 ms 75392 KB Output is correct
5 Correct 67 ms 75420 KB Output is correct
6 Correct 67 ms 75444 KB Output is correct
7 Correct 111 ms 78636 KB Output is correct
8 Correct 99 ms 78644 KB Output is correct
9 Correct 99 ms 78516 KB Output is correct
10 Correct 92 ms 76524 KB Output is correct
11 Correct 97 ms 78660 KB Output is correct
12 Correct 100 ms 76528 KB Output is correct
13 Correct 99 ms 78700 KB Output is correct
14 Correct 97 ms 78784 KB Output is correct
15 Correct 108 ms 78648 KB Output is correct
16 Correct 97 ms 78612 KB Output is correct
17 Correct 84 ms 76112 KB Output is correct
18 Correct 84 ms 76388 KB Output is correct
19 Correct 2021 ms 197896 KB Output is correct
20 Correct 2051 ms 197976 KB Output is correct
21 Correct 2077 ms 197936 KB Output is correct
22 Correct 435 ms 111604 KB Output is correct
23 Correct 1082 ms 198820 KB Output is correct
24 Correct 356 ms 112384 KB Output is correct
25 Correct 2208 ms 198856 KB Output is correct
26 Correct 2028 ms 194812 KB Output is correct
27 Correct 1775 ms 194852 KB Output is correct
28 Correct 942 ms 198688 KB Output is correct
29 Correct 229 ms 96412 KB Output is correct
30 Correct 367 ms 102420 KB Output is correct
31 Correct 2185 ms 198828 KB Output is correct
32 Correct 2094 ms 198936 KB Output is correct
33 Correct 2020 ms 198836 KB Output is correct
34 Correct 521 ms 112396 KB Output is correct
35 Correct 1116 ms 198924 KB Output is correct
36 Correct 368 ms 112392 KB Output is correct
37 Correct 2252 ms 198936 KB Output is correct
38 Correct 2307 ms 198852 KB Output is correct
39 Correct 2399 ms 197520 KB Output is correct
40 Correct 918 ms 198836 KB Output is correct
41 Correct 236 ms 96348 KB Output is correct
42 Correct 354 ms 102492 KB Output is correct
43 Correct 2359 ms 213516 KB Output is correct
44 Correct 2384 ms 213464 KB Output is correct
45 Correct 2317 ms 213564 KB Output is correct
46 Correct 488 ms 112444 KB Output is correct
47 Correct 1233 ms 213556 KB Output is correct
48 Correct 393 ms 112188 KB Output is correct
49 Correct 2420 ms 213596 KB Output is correct
50 Correct 2295 ms 213580 KB Output is correct
51 Correct 2350 ms 213504 KB Output is correct
52 Correct 1051 ms 213452 KB Output is correct
53 Correct 318 ms 96224 KB Output is correct