답안 #249041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
249041 2020-07-14T08:41:14 Z crossing0ver 이상한 기계 (APIO19_strange_device) C++17
20 / 100
2486 ms 524292 KB
#include<bits/stdc++.h>
#define inf 2000000000000000000
#define ll long long
using namespace std;

struct tre{
	ll lazy,sum,L,R;
	tre() {
		lazy = sum = L = R = 0;
	}
};
vector<tre>t(1);

void push(ll v,ll tl,ll tr,ll L,ll R) {
	ll tm = (tl + tr)/2;
	if (t[v].lazy) {
		t[L].lazy = t[R].lazy = 1;
		t[L].sum = tm - tl+1;
		t[R].sum = tr - tm;
		t[v].lazy = 0;
	}
}

void upd(ll v,ll tl,ll tr,ll l,ll r) {
	if (l > tr || r < tl) return;
	if (l <= tl && r >= tr) {
		t[v].lazy = 1;
		t[v].sum = tr - tl + 1;
		return;
	}
	ll tm = (tl + tr)/2;
	if (t[v].L == 0) {
		t[v].L = t.size();
		t.push_back(tre());
	}
	if (t[v].R == 0) {
		t[v].R = t.size();
		t.push_back(tre());
	}
	push(v,tl,tr,t[v].L,t[v].R);
	upd(t[v].L,tl,tm,l,r);
	upd(t[v].R,tm+1,tr,l,r);
	t[v].sum = t[ t[v].L ].sum + t[ t[v].R ].sum;
}


main() {
	ll n,a,b;
	cin >> n >> a >> b;
	ll m = a/(__gcd(a,b+1));
	if (m > inf/b) m = inf;
	else m*=b;
	
		for (ll l,r;n--;) {
		cin >> l >> r;
		if (r - l + 1 >= m) {
			cout << m <<'\n';
			exit(0);
		}
		l%=m;
		r%=m;
		if ( l <= r) {
			upd(0,0,m-1,l,r);
		//	cout << t[0].sum <<'\n';
		}
		else {
			upd(0,0,m-1,l,m-1);
			upd(0,0,m-1,0,r);
		}
	}
	cout << t[0].sum;
	
}

Compilation message

strange_device.cpp:47:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 29 ms 4928 KB Output is correct
3 Correct 29 ms 4968 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 28 ms 4968 KB Output is correct
17 Correct 244 ms 11100 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 4 ms 1528 KB Output is correct
3 Correct 4 ms 1528 KB Output is correct
4 Correct 4 ms 1528 KB Output is correct
5 Correct 1770 ms 1128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2486 ms 67524 KB Output is correct
3 Runtime error 1330 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2486 ms 67524 KB Output is correct
3 Runtime error 1330 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2486 ms 67524 KB Output is correct
3 Runtime error 1330 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 337 ms 69144 KB Output is correct
3 Correct 442 ms 134504 KB Output is correct
4 Runtime error 1144 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 29 ms 4928 KB Output is correct
3 Correct 29 ms 4968 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 28 ms 4968 KB Output is correct
17 Correct 244 ms 11100 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 4 ms 1528 KB Output is correct
26 Correct 4 ms 1528 KB Output is correct
27 Correct 4 ms 1528 KB Output is correct
28 Correct 1770 ms 1128 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 2486 ms 67524 KB Output is correct
31 Runtime error 1330 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
32 Halted 0 ms 0 KB -