Submission #131833

# Submission time Handle Problem Language Result Execution time Memory
131833 2019-07-17T18:27:02 Z ekrem Examination (JOI19_examination) C++
2 / 100
3000 ms 21420 KB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define orta ((bas+son)/2)
#define oorta ((bbas+sson)/2)
#define mod 1000000007
#define inf 1000000009
#define LOGN 30
#define N 100005
#define MAXN 100005
#define M N * LOGN * LOGN
using namespace std;
 
typedef int ll;
typedef pair < int , int > ii;
 
int n, m, k, q, ans[N];
pair < int , ii > a[N];
pair < ii , ii > b[N];
int son1 = 1, son2, sol[MAXN], sag[MAXN], seg[MAXN], sl[MAXN], sg[MAXN], bas[MAXN], son[MAXN];
ll val[MAXN];
 
ll opr(ll X, ll Y) {
	return X + Y;
}
 
 
int ver(int k){
	if(!k)return 0;
	if(!seg[k]){
		son2++;
		bas[son2] = 1;
		son[son2] = m;
		return seg[k] = son2;
	}
	else
		return seg[k];
}

int yeniver(int bs, int sn){
	++son2;
	bas[son2]=bs;
	son[son2]=sn;
	return son2;
}
 
int slver(int k){
	return (!sl[k])?sl[k] = ++son2:sl[k];
}
 
int sgver(int k){
	return (!sg[k])?sg[k] = ++son2:sg[k];
}
 
int solver(int k){
	return (!sol[k])?sol[k] = ++son1:sol[k];
}
 
int sagver(int k){
	return (!sag[k])?sag[k] = ++son1:sag[k];
}
 
ll qu2(int k, int x, int y){
	if(!k or bas[k] > y or son[k] < x)
		return 0;
	if(bas[k] >= x and son[k] <= y)
		return val[k];
	return opr(qu2(sl[k], x, y), qu2(sg[k], x, y));
}
 
ll qu1(int k, int bas, int son, int x, int y, int xx, int yy){
	if(!k or bas > y or son < x)
		return 0;
	if(bas >= x and son <= y)
		return qu2(seg[k], xx, yy);
	return opr(qu1(sol[k], bas, orta, x, y, xx, yy), qu1(sag[k], orta + 1, son, x, y, xx, yy));
}
 
void up2(int k, int x, ll z){
	if(bas[k] == son[k]){
		val[k] += z;
		return;
	}
	int git = (x <= ((bas[k]+son[k])/2)) ? sl[k] : sg[k];
	if(!git){
		int of = ((x <= ((bas[k]+son[k])/2)) ? sl[k] : sg[k]) = yeniver(x, x);
		val[of] += z;
	}
	else if(bas[git] <= x and son[git] >= x)
			up2(git, x, z);
	else{
		int	bbas = bas[k], sson = son[k];
		do{
			if(x <= oorta)
				sson = oorta;
			else
				bbas = oorta + 1;
		}while((x <= oorta) == (bas[git] <= oorta) );
		int of = ((x <= ((bas[k]+son[k])/2)) ? sl[k] : sg[k]) = yeniver(bbas, sson);
		(bas[git] <= oorta ? sl[of] : sg[of]) = git;
		up2(of, x, z);
	}
	val[k] = opr(val[sl[k]], val[sg[k]]);
}
 
void up1(int k, int bas, int son, int x, int y, ll z){
	if(bas == son){
		up2(ver(k), y, z);
		return;
	}
	if(x <= orta)
		up1(solver(k), bas, orta, x, y, z);
	else
		up1(sagver(k), orta + 1, son, x, y, z);
	up2(ver(k), y, z);
}

map < int , int > h, hh, x, xx;
map < int , int > :: iterator it;
 
int main(){
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d",&k ,&q);
	for(int i = 1; i <= k; i++){
		scanf("%d %d",&a[i].nd.st ,&a[i].nd.nd);
		a[i].st = a[i].nd.st + a[i].nd.nd;
		h[a[i].nd.st] = 1;
		hh[a[i].nd.nd] = 1;
	}
	sort(a + 1, a + k + 1);
	for(int i = 1; i <= q; i++){
		scanf("%d %d %d" ,&b[i].nd.st ,&b[i].nd.nd,&b[i].st.st);
		h[b[i].nd.st] = 1;
		hh[b[i].nd.nd] = 1;
		b[i].st.nd = i;
	}
	for(it = h.begin(); it != h.end(); it++)
		x[it->st] = ++n;
 
	for(it = hh.begin(); it != hh.end(); it++)
		xx[it->st] = ++m;
	// cout << n << " " << m << endl;
	sort(b + 1, b + q + 1);
	reverse(b + 1, b + q + 1);
	for(int i = 1; i <= q; i++){
		while(k >= 1 and a[k].st >= b[i].st.st){
			// cout << ne[a[k].nd.st] << " " << nee[a[k].nd.nd] << " geldi" << endl << endl;
			// cout << x[a[k].nd.st] << " " << xx[a[k].nd.nd] << " geldi" << endl;
			// int of = qu1(1, 1, n, x[a[k].nd.st],x[a[k].nd.st], xx[a[k].nd.nd],xx[a[k].nd.nd]);
			up1(1, 1, n, x[a[k].nd.st], xx[a[k].nd.nd], 1);
			k--;
		}
		// cout << b[i].st.nd << " icin bul " << n << " " << m << endl;
		// cout << x[b[i].nd.st] << " " << xx[b[i].nd.nd] << endl;
		ans[b[i].st.nd] = qu1(1, 1, n, x[b[i].nd.st], n, xx[b[i].nd.nd], m );
	}
	for(int i = 1; i <= q; i++)
		printf("%d\n", ans[i]);
	return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:126:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&k ,&q);
  ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:128:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&a[i].nd.st ,&a[i].nd.nd);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:135:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d" ,&b[i].nd.st ,&b[i].nd.nd,&b[i].st.st);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 24 ms 3324 KB Output is correct
8 Correct 23 ms 3192 KB Output is correct
9 Correct 24 ms 3184 KB Output is correct
10 Correct 12 ms 1784 KB Output is correct
11 Correct 11 ms 1528 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 24 ms 3320 KB Output is correct
14 Correct 24 ms 3292 KB Output is correct
15 Correct 24 ms 3320 KB Output is correct
16 Correct 9 ms 1276 KB Output is correct
17 Correct 10 ms 1400 KB Output is correct
18 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3037 ms 21420 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3037 ms 21420 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 24 ms 3324 KB Output is correct
8 Correct 23 ms 3192 KB Output is correct
9 Correct 24 ms 3184 KB Output is correct
10 Correct 12 ms 1784 KB Output is correct
11 Correct 11 ms 1528 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 24 ms 3320 KB Output is correct
14 Correct 24 ms 3292 KB Output is correct
15 Correct 24 ms 3320 KB Output is correct
16 Correct 9 ms 1276 KB Output is correct
17 Correct 10 ms 1400 KB Output is correct
18 Correct 4 ms 504 KB Output is correct
19 Execution timed out 3037 ms 21420 KB Time limit exceeded
20 Halted 0 ms 0 KB -