Submission #126150

# Submission time Handle Problem Language Result Execution time Memory
126150 2019-07-07T06:09:37 Z dndhk Examination (JOI19_examination) C++14
43 / 100
3000 ms 384784 KB
#include <bits/stdc++.h>

#define pb push_back
#define all(v) ((v).begin(), (v).end())
#define sortv(v) sort(all(v))
#define sz(v) ((int)(v).size())
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define umax(a, b) (a)=max((a), (b))
#define umin(a, b) (a)=min((a), (b))
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,n) FOR(i,1,n)
#define rep0(i,n) FOR(i,0,(int)(n)-1)
#define FI first
#define SE second
#define INF 1000000000
#define INFLL 1000000000000000000LL

const int MAX_N = 100000;

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int NX, NY;


struct S{
	S(int a, int b, int c) : a(a), b(b), c(c) {}
	int a, b, c;
	bool operator <(const S &t)const{
		return a<t.a;
	}
};

vector<S> vt, vt2;

struct SEG{
	struct Node{
		Node(int l, int r, int sum) : l(l), r(r), sum(sum) {}
		int l, r;
		int sum;
	};
	vector<Node> seg;
	void Init(){
		seg.pb({-1, -1, 0});
	}
	void Update(int x){
		//printf("%d\n", x);
		update(0, 0, NY, x);
	}
	void update(int idx, int s, int e, int k){
		while(1){
			seg[idx].sum++;
			if(s==e)	return;
			if(k<=(s+e)/2){
				if(seg[idx].l==-1){
					seg[idx].l = seg.size(); seg.pb({-1, -1, 0});
				}
				idx = seg[idx].l; e = (s+e)/2;
			}else{
				if(seg[idx].r == -1){
					seg[idx].r = seg.size(); seg.pb({-1, -1, 0});
				}
				idx = seg[idx].r; s = (s+e)/2+1;
			}
		}
	}
	int Sum(int x, int y){
		//cout<<x<<" "<<y<<endl;
		int ret = 0;
		int idx, s, e;
		vt.pb({0, 0, NY});
		while(!vt.empty()){
			idx = vt.back().a; s = vt.back().b; e = vt.back().c; vt.pop_back();
			if(idx==-1)	continue;
			if(x<=s && e<=y){
				ret += seg[idx].sum;
				continue;
			}
			if(x>e || y<s)	continue;
			vt.pb({seg[idx].l, s, (s+e)/2}); vt.pb({seg[idx].r, (s+e)/2+1, e});
		}
		return ret;
	}/*
	int sum(int idx, int s, int e, int x, int y){
		if(x==-1)	return 0;
		if(x<=s && e<=y)	{
			//if(seg[idx].sum!=0)	cout<<s<<" "<<e<<" "<<seg[idx].sum<<endl;
			return seg[idx].sum;
		}
		if(x>e || y<s)	return 0;
		return sum(seg[idx].l, s, (s+e)/2, x, y) + sum(seg[idx].r, (s+e)/2+1, e, x, y);
	}*/
};

vector<SEG> tree;
SEG tSEG;

struct SEG2{
	struct Node{
		Node(int l, int r, int num) : l(l), r(r), num(num) {}
		int l, r, num;
	};
	vector<Node> seg;
	int N;
	void Init(){
		N = INF;
		seg.pb({-1, -1, -1});
	}
	vector<int> vt;
	void Update(int x, int y){
		update(0, 0, NX, x);
		for(int i=0; i<vt.size(); i++){
			tree[vt[i]].Update(y);
		}
		vt.clear();
	}
	void update(int idx, int s, int e, int k){
		while(1){
			if(seg[idx].num==-1){
				seg[idx].num = tree.size(); tree.pb(tSEG); tree[seg[idx].num].Init();
			}
			vt.pb(seg[idx].num);
			if(s==e)	return;
			if(k<=(s+e)/2){
				if(seg[idx].l==-1){
					seg[idx].l = seg.size(); seg.pb({-1, -1, -1});
				}
				idx = seg[idx].l; e = (s+e)/2;
			}else{
				if(seg[idx].r == -1){
					seg[idx].r = seg.size(); seg.pb({-1, -1, -1});
				}
				idx = seg[idx].r; s = (s+e)/2+1;
			}
		}
	}
	int Sum(int x, int y, int z, int w){
		vt2.pb({0, 0, NX});
		int ret=0;
		int idx, s, e;
		while(!vt2.empty()){
			idx = vt2.back().a; s = vt2.back().b; e = vt2.back().c;	vt2.pop_back();
			if(idx==-1)	continue;
			if(seg[idx].num==-1)	continue;
			if(x<=s && e<=y)	{
				ret += tree[seg[idx].num].Sum(z, w);
				continue;
			}
			if(x>e || y<s)	continue;
			vt2.pb({seg[idx].l, s, (s+e)/2}); vt2.pb({seg[idx].r, (s+e)/2+1, e});
		}
		return ret;
	}
	/*
	int sum(int idx, int s, int e, int x, int y, int z, int w){
		if(idx==-1)	return 0;
		if(seg[idx].num==-1)	return 0;
		if(x<=s && e<=y){
			//cout<<s<<" "<<e<<" "<<z<<" "<<w<<" "<<tree[seg[idx].num].Sum(z, w)<<endl;
			return tree[seg[idx].num].Sum(z, w);
		}
		if(x>e || y<s)	return 0;
		return sum(seg[idx].l, s, (s+e)/2, x, y, z, w) + sum(seg[idx].r, (s+e)/2+1, e, x, y, z, w);
	}*/
};

SEG2 Seg;

int M, Q;
struct Query{
	Query(int a, int b, int c, int idx) : a(a), b(b), c(c), idx(idx) {}
	int a, b, c;
	int idx;
	bool operator <(const Query &t)const{
		return a<t.a;
	}
};

map<int, int> X, Y;
vector<int> vx, vy;
vector<S> v;
vector<Query> query;
int ans[MAX_N+1];

void cord(){
	sort(vx.begin(), vx.end()); sort(vy.begin(), vy.end());
	vx.erase(unique(vx.begin(), vx.end()), vx.end()); vy.erase(unique(vy.begin(), vy.end()), vy.end());
	for(int i=0; i<vx.size(); i++){
		X[vx[i]] = i;
	}
	for(int i=0; i<vy.size(); i++){
		Y[vy[i]] = i;
	}
	NX = vx.size()-1; NY = vy.size()-1;
}

int main(){
	scanf("%d%d", &M, &Q);
	for(int i=0; i<M; i++){
		int a, b; scanf("%d%d", &a, &b);
		vx.pb(a); vy.pb(b);
		v.pb({a+b, a, b});
	}
	for(int i=0; i<Q; i++){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		vx.pb(a); vy.pb(b);
		query.pb({c, a, b, i});
	}
	cord();
	sort(v.begin(), v.end());
	sort(query.begin(), query.end());
	Seg.Init();
	while(!query.empty()){
		if(v.empty() || query.back().a > v.back().a){
			Query now = query.back(); query.pop_back();
			ans[now.idx] = Seg.Sum(X[now.b], NX, Y[now.c], NY);
			//cout<<endl;
		}else{
			S now = v.back(); v.pop_back();
			//cout<<now.a<<" "<<now.b<<" "<<now.c<<endl<<"======================="<<endl;
			Seg.Update(X[now.b], Y[now.c]);
		}	
	}
	for(int i=0; i<Q; i++){
		printf("%d\n", ans[i]);
	}

	return 0;
}

Compilation message

examination.cpp: In member function 'void SEG2::Update(int, int)':
examination.cpp:114:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0; i<vt.size(); i++){
                ~^~~~~~~~~~
examination.cpp: In function 'void cord()':
examination.cpp:190:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<vx.size(); i++){
               ~^~~~~~~~~~
examination.cpp:193:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<vy.size(); i++){
               ~^~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:200:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &M, &Q);
  ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:202:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a, b; scanf("%d%d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:208:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &a, &b, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 40 ms 7492 KB Output is correct
8 Correct 33 ms 7260 KB Output is correct
9 Correct 33 ms 7288 KB Output is correct
10 Correct 15 ms 2552 KB Output is correct
11 Correct 12 ms 1860 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 37 ms 7372 KB Output is correct
14 Correct 35 ms 7288 KB Output is correct
15 Correct 35 ms 7288 KB Output is correct
16 Correct 8 ms 1272 KB Output is correct
17 Correct 11 ms 1788 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2491 ms 279472 KB Output is correct
2 Correct 2418 ms 279344 KB Output is correct
3 Correct 2526 ms 279732 KB Output is correct
4 Correct 551 ms 38856 KB Output is correct
5 Correct 437 ms 30504 KB Output is correct
6 Correct 119 ms 6640 KB Output is correct
7 Correct 2489 ms 266388 KB Output is correct
8 Correct 2358 ms 266000 KB Output is correct
9 Correct 2181 ms 254476 KB Output is correct
10 Correct 252 ms 15500 KB Output is correct
11 Correct 399 ms 20496 KB Output is correct
12 Correct 82 ms 6184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2491 ms 279472 KB Output is correct
2 Correct 2418 ms 279344 KB Output is correct
3 Correct 2526 ms 279732 KB Output is correct
4 Correct 551 ms 38856 KB Output is correct
5 Correct 437 ms 30504 KB Output is correct
6 Correct 119 ms 6640 KB Output is correct
7 Correct 2489 ms 266388 KB Output is correct
8 Correct 2358 ms 266000 KB Output is correct
9 Correct 2181 ms 254476 KB Output is correct
10 Correct 252 ms 15500 KB Output is correct
11 Correct 399 ms 20496 KB Output is correct
12 Correct 82 ms 6184 KB Output is correct
13 Correct 2446 ms 279720 KB Output is correct
14 Correct 2707 ms 279824 KB Output is correct
15 Correct 2538 ms 279656 KB Output is correct
16 Correct 510 ms 38848 KB Output is correct
17 Correct 394 ms 30412 KB Output is correct
18 Correct 123 ms 6552 KB Output is correct
19 Correct 2320 ms 279740 KB Output is correct
20 Correct 2453 ms 280568 KB Output is correct
21 Correct 2045 ms 265824 KB Output is correct
22 Correct 249 ms 15556 KB Output is correct
23 Correct 391 ms 20496 KB Output is correct
24 Correct 79 ms 6292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 40 ms 7492 KB Output is correct
8 Correct 33 ms 7260 KB Output is correct
9 Correct 33 ms 7288 KB Output is correct
10 Correct 15 ms 2552 KB Output is correct
11 Correct 12 ms 1860 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 37 ms 7372 KB Output is correct
14 Correct 35 ms 7288 KB Output is correct
15 Correct 35 ms 7288 KB Output is correct
16 Correct 8 ms 1272 KB Output is correct
17 Correct 11 ms 1788 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 2491 ms 279472 KB Output is correct
20 Correct 2418 ms 279344 KB Output is correct
21 Correct 2526 ms 279732 KB Output is correct
22 Correct 551 ms 38856 KB Output is correct
23 Correct 437 ms 30504 KB Output is correct
24 Correct 119 ms 6640 KB Output is correct
25 Correct 2489 ms 266388 KB Output is correct
26 Correct 2358 ms 266000 KB Output is correct
27 Correct 2181 ms 254476 KB Output is correct
28 Correct 252 ms 15500 KB Output is correct
29 Correct 399 ms 20496 KB Output is correct
30 Correct 82 ms 6184 KB Output is correct
31 Correct 2446 ms 279720 KB Output is correct
32 Correct 2707 ms 279824 KB Output is correct
33 Correct 2538 ms 279656 KB Output is correct
34 Correct 510 ms 38848 KB Output is correct
35 Correct 394 ms 30412 KB Output is correct
36 Correct 123 ms 6552 KB Output is correct
37 Correct 2320 ms 279740 KB Output is correct
38 Correct 2453 ms 280568 KB Output is correct
39 Correct 2045 ms 265824 KB Output is correct
40 Correct 249 ms 15556 KB Output is correct
41 Correct 391 ms 20496 KB Output is correct
42 Correct 79 ms 6292 KB Output is correct
43 Correct 2791 ms 384784 KB Output is correct
44 Correct 2735 ms 384332 KB Output is correct
45 Execution timed out 3039 ms 384204 KB Time limit exceeded
46 Halted 0 ms 0 KB -