답안 #613205

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
613205 2022-07-30T03:58:39 Z temporary_juggernaut Examination (JOI19_examination) C++14
100 / 100
1756 ms 211528 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef juggernaut
    #define printl(args...) printf(args)
#else
    #define printl(args...) 0
#endif
vector<array<int,4>>vec;
int ans[100005];
const int N=2e5;
struct SegmentTree{
	struct node{
		int lson,rson,sum;
		node(){
			lson=rson=sum=0;
		}
	};
	vector<node>tree={node(),node()};
	int timer=2;
	void update(int pos,int v=1,int l=1,int r=N){
		tree[v].sum++;
		if(l==r)return;
		int mid=(l+r)>>1;
		if(pos<=mid){
			if(!tree[v].lson){
				tree.push_back(node());
				tree[v].lson=timer++;
			}
			update(pos,tree[v].lson,l,mid);
		}else{
			if(!tree[v].rson){
				tree.push_back(node());
				tree[v].rson=timer++;
			}
			update(pos,tree[v].rson,mid+1,r);
		}
	}
	int get(int ql,int qr,int v=1,int l=1,int r=N){
		if(r<ql||qr<l||!v)return 0;
		if(ql<=l&&r<=qr)return tree[v].sum;
		int mid=(l+r)>>1;
		return get(ql,qr,tree[v].lson,l,mid)+get(ql,qr,tree[v].rson,mid+1,r);
	}
}fen[200005];
void add(int x,int y){
	for(;x<=N;x+=(x&-x))fen[x].update(y);
}
int sum(int x,int y){
	int ans=0;
	for(;x;x-=(x&-x))ans+=fen[x].get(y,N);
	return ans;
}
int gt(int x,int y){
	return sum(N,y)-sum(x-1,y);
}
int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	vector<int>X,Y;
	for(int i=1;i<=n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		X.push_back(x);
		Y.push_back(y);
		vec.push_back({-x-y,0,x,y});
	}
	for(int i=1;i<=q;i++){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		X.push_back(x);
		Y.push_back(y);
		vec.push_back({-z,i,x,y});
	}
	sort(vec.begin(),vec.end());
	sort(X.begin(),X.end());
	X.erase(unique(X.begin(),X.end()),X.end());
	sort(Y.begin(),Y.end());
	Y.erase(unique(Y.begin(),Y.end()),Y.end());
	map<int,int>idx,idy;
	int timer=1;
	for(int to:X)idx[to]=timer++;
	timer=1;
	for(int to:Y)idy[to]=timer++;
	for(auto query:vec){
		query[2]=idx[query[2]];
		query[3]=idy[query[3]];
		if(!query[1])add(query[2],query[3]);
		else ans[query[1]]=gt(query[2],query[3]);
	}
	for(int i=1;i<=q;i++)printf("%d\n",ans[i]);
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:64:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |  scanf("%d%d",&n,&q);
      |  ~~~~~^~~~~~~~~~~~~~
examination.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
examination.cpp:75:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |   scanf("%d%d%d",&x,&y,&z);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12756 KB Output is correct
2 Correct 14 ms 12756 KB Output is correct
3 Correct 18 ms 12844 KB Output is correct
4 Correct 13 ms 12856 KB Output is correct
5 Correct 12 ms 12824 KB Output is correct
6 Correct 12 ms 12756 KB Output is correct
7 Correct 36 ms 17748 KB Output is correct
8 Correct 43 ms 17708 KB Output is correct
9 Correct 40 ms 17768 KB Output is correct
10 Correct 26 ms 14940 KB Output is correct
11 Correct 33 ms 15972 KB Output is correct
12 Correct 24 ms 13116 KB Output is correct
13 Correct 47 ms 17816 KB Output is correct
14 Correct 41 ms 17900 KB Output is correct
15 Correct 50 ms 17832 KB Output is correct
16 Correct 30 ms 16260 KB Output is correct
17 Correct 27 ms 14780 KB Output is correct
18 Correct 25 ms 13120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1691 ms 163160 KB Output is correct
2 Correct 1505 ms 162972 KB Output is correct
3 Correct 1499 ms 162840 KB Output is correct
4 Correct 587 ms 53340 KB Output is correct
5 Correct 557 ms 70144 KB Output is correct
6 Correct 229 ms 19816 KB Output is correct
7 Correct 1202 ms 156612 KB Output is correct
8 Correct 1368 ms 156360 KB Output is correct
9 Correct 1152 ms 151456 KB Output is correct
10 Correct 457 ms 72572 KB Output is correct
11 Correct 383 ms 50208 KB Output is correct
12 Correct 209 ms 19488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1691 ms 163160 KB Output is correct
2 Correct 1505 ms 162972 KB Output is correct
3 Correct 1499 ms 162840 KB Output is correct
4 Correct 587 ms 53340 KB Output is correct
5 Correct 557 ms 70144 KB Output is correct
6 Correct 229 ms 19816 KB Output is correct
7 Correct 1202 ms 156612 KB Output is correct
8 Correct 1368 ms 156360 KB Output is correct
9 Correct 1152 ms 151456 KB Output is correct
10 Correct 457 ms 72572 KB Output is correct
11 Correct 383 ms 50208 KB Output is correct
12 Correct 209 ms 19488 KB Output is correct
13 Correct 1235 ms 163000 KB Output is correct
14 Correct 1414 ms 166040 KB Output is correct
15 Correct 1418 ms 165236 KB Output is correct
16 Correct 520 ms 55520 KB Output is correct
17 Correct 487 ms 72440 KB Output is correct
18 Correct 215 ms 20872 KB Output is correct
19 Correct 1291 ms 165612 KB Output is correct
20 Correct 1265 ms 165820 KB Output is correct
21 Correct 1098 ms 161504 KB Output is correct
22 Correct 434 ms 74380 KB Output is correct
23 Correct 400 ms 52004 KB Output is correct
24 Correct 205 ms 20536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12756 KB Output is correct
2 Correct 14 ms 12756 KB Output is correct
3 Correct 18 ms 12844 KB Output is correct
4 Correct 13 ms 12856 KB Output is correct
5 Correct 12 ms 12824 KB Output is correct
6 Correct 12 ms 12756 KB Output is correct
7 Correct 36 ms 17748 KB Output is correct
8 Correct 43 ms 17708 KB Output is correct
9 Correct 40 ms 17768 KB Output is correct
10 Correct 26 ms 14940 KB Output is correct
11 Correct 33 ms 15972 KB Output is correct
12 Correct 24 ms 13116 KB Output is correct
13 Correct 47 ms 17816 KB Output is correct
14 Correct 41 ms 17900 KB Output is correct
15 Correct 50 ms 17832 KB Output is correct
16 Correct 30 ms 16260 KB Output is correct
17 Correct 27 ms 14780 KB Output is correct
18 Correct 25 ms 13120 KB Output is correct
19 Correct 1691 ms 163160 KB Output is correct
20 Correct 1505 ms 162972 KB Output is correct
21 Correct 1499 ms 162840 KB Output is correct
22 Correct 587 ms 53340 KB Output is correct
23 Correct 557 ms 70144 KB Output is correct
24 Correct 229 ms 19816 KB Output is correct
25 Correct 1202 ms 156612 KB Output is correct
26 Correct 1368 ms 156360 KB Output is correct
27 Correct 1152 ms 151456 KB Output is correct
28 Correct 457 ms 72572 KB Output is correct
29 Correct 383 ms 50208 KB Output is correct
30 Correct 209 ms 19488 KB Output is correct
31 Correct 1235 ms 163000 KB Output is correct
32 Correct 1414 ms 166040 KB Output is correct
33 Correct 1418 ms 165236 KB Output is correct
34 Correct 520 ms 55520 KB Output is correct
35 Correct 487 ms 72440 KB Output is correct
36 Correct 215 ms 20872 KB Output is correct
37 Correct 1291 ms 165612 KB Output is correct
38 Correct 1265 ms 165820 KB Output is correct
39 Correct 1098 ms 161504 KB Output is correct
40 Correct 434 ms 74380 KB Output is correct
41 Correct 400 ms 52004 KB Output is correct
42 Correct 205 ms 20536 KB Output is correct
43 Correct 1620 ms 211396 KB Output is correct
44 Correct 1756 ms 211432 KB Output is correct
45 Correct 1642 ms 211528 KB Output is correct
46 Correct 605 ms 86900 KB Output is correct
47 Correct 574 ms 108276 KB Output is correct
48 Correct 251 ms 20700 KB Output is correct
49 Correct 1410 ms 195972 KB Output is correct
50 Correct 1534 ms 204936 KB Output is correct
51 Correct 1258 ms 187268 KB Output is correct
52 Correct 555 ms 111204 KB Output is correct
53 Correct 546 ms 83044 KB Output is correct