Submission #963525

# Submission time Handle Problem Language Result Execution time Memory
963525 2024-04-15T09:16:52 Z noobcodur Examination (JOI19_examination) C++14
100 / 100
557 ms 85120 KB
#include<bits/stdc++.h>
using namespace std;

using ld = long double;

#define int long long
#define pii pair<int,int>
#define forn(i,j) for(int i = 0; i < j; ++i)
#define forrange(i,j,k) for(int i = j; i < k; ++i)
#define vi vector<int>
#define vpii vector<pii>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

const int MOD = 1e9+7; const int INF = 1e17+1; const int maxN = 2e5+1;

void setIO(string name){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	if(!name.empty()){
		freopen((name + ".in").c_str(),"r",stdin);
		freopen((name + ".out").c_str(),"w",stdout);
	}
}

vi st1[4*maxN],st2[4*maxN];
vpii num;

void build(int pos, int l, int r){
	if(l == r){
		st1[pos].pb(num[l].s);
		st2[pos].pb(num[l].f + num[l].s);

		return;
	}

	int mid = (l+r)/2;
	build(2*pos,l,mid);
	build(2*pos+1,mid+1,r);

	merge(all(st1[2*pos]),all(st1[2*pos+1]),back_inserter(st1[pos]));
	merge(all(st2[2*pos]),all(st2[2*pos+1]),back_inserter(st2[pos]));
}

int query1(int pos, int l, int r, int ql, int qr, int x){
	if(l > qr || r < ql){
		return 0;
	}

	if(ql <= l && r <= qr){
		return st1[pos].end() - lower_bound(all(st1[pos]),x);
	}

	int mid = (l+r)/2;

	return query1(2*pos,l,mid,ql,qr,x) + query1(2*pos+1,mid+1,r,ql,qr,x);
}

int query2(int pos, int l, int r, int ql, int qr, int x){
	if(l > qr || r < ql) return 0;

	if(ql <= l && r <= qr){
		return st2[pos].end() - lower_bound(all(st2[pos]),x);
	}

	int mid = (l+r)/2;

	return query2(2*pos,l,mid,ql,qr,x) + query2(2*pos+1,mid+1,r,ql,qr,x);
}

signed main(){
	setIO("");
	int n,q; cin >> n >> q;
	num.resize(n);

	forn(i,n){
		cin >> num[i].f >> num[i].s;
	}

	sort(all(num));

	build(1,0,n-1);

	while(q--){
		int x,y,z; cin >> x >> y >> z;

		int d = z - y;
		int res = 0;
		if(d >= x){
			pii j = {x,0};
			int l = lower_bound(all(num),j) - num.begin();
			j = {d,0};
			int r = lower_bound(all(num),j) - num.begin() - 1;

			res += query2(1,0,n-1,l,r,z);
			x = d;
		}

		pii j = {x,0}; int l = lower_bound(all(num),j) - num.begin();

		res += query1(1,0,n-1,l,n-1,y);

		cout << res << endl;
	}
}

Compilation message

examination.cpp: In function 'void setIO(std::string)':
examination.cpp:24:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   freopen((name + ".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   freopen((name + ".out").c_str(),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 37976 KB Output is correct
2 Correct 9 ms 38028 KB Output is correct
3 Correct 8 ms 37980 KB Output is correct
4 Correct 10 ms 37976 KB Output is correct
5 Correct 10 ms 38236 KB Output is correct
6 Correct 9 ms 37980 KB Output is correct
7 Correct 18 ms 39276 KB Output is correct
8 Correct 21 ms 39260 KB Output is correct
9 Correct 18 ms 39260 KB Output is correct
10 Correct 17 ms 39228 KB Output is correct
11 Correct 16 ms 39016 KB Output is correct
12 Correct 17 ms 39156 KB Output is correct
13 Correct 18 ms 39004 KB Output is correct
14 Correct 21 ms 39232 KB Output is correct
15 Correct 18 ms 39004 KB Output is correct
16 Correct 17 ms 39516 KB Output is correct
17 Correct 16 ms 39104 KB Output is correct
18 Correct 15 ms 39000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 422 ms 83736 KB Output is correct
2 Correct 384 ms 83496 KB Output is correct
3 Correct 410 ms 83732 KB Output is correct
4 Correct 352 ms 82948 KB Output is correct
5 Correct 287 ms 82948 KB Output is correct
6 Correct 249 ms 82820 KB Output is correct
7 Correct 355 ms 83572 KB Output is correct
8 Correct 348 ms 83588 KB Output is correct
9 Correct 360 ms 83592 KB Output is correct
10 Correct 237 ms 82824 KB Output is correct
11 Correct 327 ms 82916 KB Output is correct
12 Correct 241 ms 82308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 422 ms 83736 KB Output is correct
2 Correct 384 ms 83496 KB Output is correct
3 Correct 410 ms 83732 KB Output is correct
4 Correct 352 ms 82948 KB Output is correct
5 Correct 287 ms 82948 KB Output is correct
6 Correct 249 ms 82820 KB Output is correct
7 Correct 355 ms 83572 KB Output is correct
8 Correct 348 ms 83588 KB Output is correct
9 Correct 360 ms 83592 KB Output is correct
10 Correct 237 ms 82824 KB Output is correct
11 Correct 327 ms 82916 KB Output is correct
12 Correct 241 ms 82308 KB Output is correct
13 Correct 457 ms 83820 KB Output is correct
14 Correct 419 ms 83844 KB Output is correct
15 Correct 388 ms 83588 KB Output is correct
16 Correct 461 ms 83336 KB Output is correct
17 Correct 287 ms 83228 KB Output is correct
18 Correct 272 ms 82668 KB Output is correct
19 Correct 494 ms 83856 KB Output is correct
20 Correct 469 ms 83848 KB Output is correct
21 Correct 465 ms 83788 KB Output is correct
22 Correct 251 ms 82956 KB Output is correct
23 Correct 297 ms 82884 KB Output is correct
24 Correct 235 ms 82308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 37976 KB Output is correct
2 Correct 9 ms 38028 KB Output is correct
3 Correct 8 ms 37980 KB Output is correct
4 Correct 10 ms 37976 KB Output is correct
5 Correct 10 ms 38236 KB Output is correct
6 Correct 9 ms 37980 KB Output is correct
7 Correct 18 ms 39276 KB Output is correct
8 Correct 21 ms 39260 KB Output is correct
9 Correct 18 ms 39260 KB Output is correct
10 Correct 17 ms 39228 KB Output is correct
11 Correct 16 ms 39016 KB Output is correct
12 Correct 17 ms 39156 KB Output is correct
13 Correct 18 ms 39004 KB Output is correct
14 Correct 21 ms 39232 KB Output is correct
15 Correct 18 ms 39004 KB Output is correct
16 Correct 17 ms 39516 KB Output is correct
17 Correct 16 ms 39104 KB Output is correct
18 Correct 15 ms 39000 KB Output is correct
19 Correct 422 ms 83736 KB Output is correct
20 Correct 384 ms 83496 KB Output is correct
21 Correct 410 ms 83732 KB Output is correct
22 Correct 352 ms 82948 KB Output is correct
23 Correct 287 ms 82948 KB Output is correct
24 Correct 249 ms 82820 KB Output is correct
25 Correct 355 ms 83572 KB Output is correct
26 Correct 348 ms 83588 KB Output is correct
27 Correct 360 ms 83592 KB Output is correct
28 Correct 237 ms 82824 KB Output is correct
29 Correct 327 ms 82916 KB Output is correct
30 Correct 241 ms 82308 KB Output is correct
31 Correct 457 ms 83820 KB Output is correct
32 Correct 419 ms 83844 KB Output is correct
33 Correct 388 ms 83588 KB Output is correct
34 Correct 461 ms 83336 KB Output is correct
35 Correct 287 ms 83228 KB Output is correct
36 Correct 272 ms 82668 KB Output is correct
37 Correct 494 ms 83856 KB Output is correct
38 Correct 469 ms 83848 KB Output is correct
39 Correct 465 ms 83788 KB Output is correct
40 Correct 251 ms 82956 KB Output is correct
41 Correct 297 ms 82884 KB Output is correct
42 Correct 235 ms 82308 KB Output is correct
43 Correct 482 ms 84844 KB Output is correct
44 Correct 478 ms 85120 KB Output is correct
45 Correct 464 ms 84556 KB Output is correct
46 Correct 439 ms 83824 KB Output is correct
47 Correct 291 ms 83844 KB Output is correct
48 Correct 265 ms 82428 KB Output is correct
49 Correct 493 ms 84824 KB Output is correct
50 Correct 432 ms 84428 KB Output is correct
51 Correct 557 ms 84832 KB Output is correct
52 Correct 261 ms 83648 KB Output is correct
53 Correct 308 ms 83428 KB Output is correct