Submission #568798

# Submission time Handle Problem Language Result Execution time Memory
568798 2022-05-26T08:19:20 Z HappyPacMan Strange Device (APIO19_strange_device) C++14
20 / 100
801 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;

struct Node{
	ll v;
	bool f;
	Node *lf,*rg;
	Node(){
		v = f = false;
		lf = rg = NULL;
	}
};

void upd(Node *i,ll l,ll r,ll ul,ll ur){
	if(ul > r || ur < l){
		return;
	}
	if(ul <= l && r <= ur){
		i->v = r-l+1;
		i->f = true;
		return;
	}
	int m = (l+r)/2;
	if(i->lf == NULL){
		i->lf = new Node();
	}
	if(i->rg == NULL){
		i->rg = new Node();
	}
	if(i->f){
		i->lf->v = m-l+1;
		i->lf->f = true;
		i->rg->v = r-m;
		i->rg->f = true;
	}
	upd(i->lf,l,m,ul,ur);
	upd(i->rg,m+1,r,ul,ur);
	i->v = i->lf->v + i->rg->v;
	if(i->v == r-l+1){
		i->f = true;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	ll A,B;
	cin >> n >> A >> B;
	__int128_t LC = (__int128_t)1*A/__gcd(A,B+1)*B;
	ll sum = 0;
	vector<pair<ll,ll> > range;
	for(int i=0;i<n;i++){
		ll li,ri;
		cin >> li >> ri;
		sum += ri-li+1;
		range.emplace_back(li,ri);
	}
	if(LC > (__int128_t)inf){
		cout << sum << '\n';
		return 0;
	}
	ll LCM = A/__gcd(A,B+1)*B;
	Node *root = new Node();
	for(auto [li,ri] : range){
		if(ri/LCM-li/LCM > 1){
			upd(root,0,LCM-1,0,LCM-1);
		}else if(ri/LCM-li/LCM == 1){
			upd(root,0,LCM-1,li%LCM,LCM-1);
			upd(root,0,LCM-1,0,ri%LCM);
		}else{
			upd(root,0,LCM-1,li%LCM,ri%LCM);
		}
	}
	cout << root->v << '\n';
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:68:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   68 |  for(auto [li,ri] : range){
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 10 ms 4320 KB Output is correct
3 Correct 11 ms 5080 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 9 ms 3920 KB Output is correct
17 Correct 60 ms 11584 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 4 ms 1460 KB Output is correct
3 Correct 2 ms 1364 KB Output is correct
4 Correct 2 ms 1364 KB Output is correct
5 Correct 445 ms 17704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 591 ms 110000 KB Output is correct
3 Runtime error 801 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 591 ms 110000 KB Output is correct
3 Runtime error 801 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 591 ms 110000 KB Output is correct
3 Runtime error 801 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 132 ms 65032 KB Output is correct
3 Runtime error 436 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 10 ms 4320 KB Output is correct
3 Correct 11 ms 5080 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 9 ms 3920 KB Output is correct
17 Correct 60 ms 11584 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 4 ms 1460 KB Output is correct
26 Correct 2 ms 1364 KB Output is correct
27 Correct 2 ms 1364 KB Output is correct
28 Correct 445 ms 17704 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 591 ms 110000 KB Output is correct
31 Runtime error 801 ms 524288 KB Execution killed with signal 9
32 Halted 0 ms 0 KB -