답안 #975628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975628 2024-05-05T15:04:14 Z Batorgil952 이상한 기계 (APIO19_strange_device) C++14
20 / 100
529 ms 524288 KB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair

using namespace std;

const ll N=1e7+7;
struct Node{
	ll l;
	ll r;
	ll vl=-1;
	ll vr=-1;
	ll val=0;
};
Node tree[N];
ll K;

ll GCD(ll x, ll y){
	while(x*y!=0){
		if(x>y) x%=y;
		else y%=x;
	}
	return x+y;
}

void update(ll v, ll ql, ll qr){
	if(tree[v].val==tree[v].r-tree[v].l+1){
		return;
	}
	if(qr<tree[v].l && tree[v].r<ql){
		return;
	}
	if(ql<=tree[v].l && tree[v].r<=qr){
		tree[v].val=tree[v].r-tree[v].l+1;
		return;
	}
	ll mid=(tree[v].l+tree[v].r)/2;
	if(qr<=mid){
		if(tree[v].vl==-1){
			K++;
			tree[v].vl=K;
			tree[tree[v].vl].l=tree[v].l;
			tree[tree[v].vl].r=mid;
			update(tree[v].vl, ql, qr);
		}
		else if(tree[tree[v].vl].val!=mid-tree[v].l+1){
			update(tree[v].vl, ql, qr);
		}
	}
	else if(mid+1<=ql){
		if(tree[v].vr==-1){
			K++;
			tree[v].vr=K;
			tree[tree[v].vr].l=mid+1;
			tree[tree[v].vr].r=tree[v].r;
			update(tree[v].vr, ql, qr);
		}
		else if(tree[tree[v].vr].val!=tree[v].r-mid){
			update(tree[v].vr, ql, qr);
		}
	}
	else{
		if(tree[v].vl==-1){
			K++;
			tree[v].vl=K;
			tree[tree[v].vl].l=tree[v].l;
			tree[tree[v].vl].r=mid;
			update(tree[v].vl, ql, qr);
		}
		else if(tree[tree[v].vl].val!=mid-tree[v].l+1){
			update(tree[v].vl, ql, qr);
		}
		if(tree[v].vr==-1){
			K++;
			tree[v].vr=K;
			tree[tree[v].vr].l=mid+1;
			tree[tree[v].vr].r=tree[v].r;
			update(tree[v].vr, ql, qr);
		}
		else if(tree[tree[v].vr].val!=tree[v].r-mid){
			update(tree[v].vr, ql, qr);
		}
	}
	tree[v].val=tree[tree[v].vl].val+tree[tree[v].vr].val;
//	cout<<v<<" "<<ql<<" "<<qr<<" "<<tree[v].l<<" "<<tree[v].r<<" "<<tree[v].val<<endl;
	
}

ll query(ll v, ll l, ll r){
	return tree[v].val;
}


int main(){
	ll n, i, A, B, l, r, k, m, ma;
	
	scanf("%lld",&n);
	scanf("%lld",&A);
	scanf("%lld",&B);
	
	m=GCD(B+1, A);
	A/=m;
	ma=1000000000000000002;
	if(ma/A<B){
		k=ma;
	}
	else{
		k=A*B;
	}
//	cout<<k<<endl;
	
	tree[0].l=0;
	tree[0].r=k-1;
	K=0;
	for(i=1; i<=n; i++){
		scanf("%lld",&l);
		scanf("%lld",&r);
		if(r-l+1>=k) update(0, 0, k-1);
		else{
			if(l%k<=r%k){
				update(0, l%k, r%k);
			}
			else{
				update(0, l%k, k-1);
				update(0, 0, r%k);
			}
		}
	}
	
	printf("%lld\n", query(0, 0, k-1));
	
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:98:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |  scanf("%lld",&n);
      |  ~~~~~^~~~~~~~~~~
strange_device.cpp:99:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |  scanf("%lld",&A);
      |  ~~~~~^~~~~~~~~~~
strange_device.cpp:100:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |  scanf("%lld",&B);
      |  ~~~~~^~~~~~~~~~~
strange_device.cpp:117:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |   scanf("%lld",&l);
      |   ~~~~~^~~~~~~~~~~
strange_device.cpp:118:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |   scanf("%lld",&r);
      |   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 175 ms 391596 KB Output is correct
2 Correct 127 ms 392112 KB Output is correct
3 Correct 127 ms 392160 KB Output is correct
4 Correct 122 ms 391852 KB Output is correct
5 Correct 119 ms 391564 KB Output is correct
6 Correct 121 ms 391668 KB Output is correct
7 Correct 124 ms 391812 KB Output is correct
8 Correct 121 ms 391804 KB Output is correct
9 Correct 119 ms 391580 KB Output is correct
10 Correct 118 ms 391664 KB Output is correct
11 Correct 126 ms 391628 KB Output is correct
12 Correct 133 ms 391652 KB Output is correct
13 Correct 120 ms 391740 KB Output is correct
14 Correct 125 ms 391664 KB Output is correct
15 Correct 120 ms 391636 KB Output is correct
16 Correct 124 ms 392108 KB Output is correct
17 Correct 160 ms 393832 KB Output is correct
18 Correct 131 ms 391836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 391640 KB Output is correct
2 Correct 119 ms 391784 KB Output is correct
3 Correct 119 ms 391760 KB Output is correct
4 Correct 123 ms 391868 KB Output is correct
5 Correct 118 ms 391744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 391764 KB Output is correct
2 Correct 120 ms 391616 KB Output is correct
3 Correct 121 ms 391628 KB Output is correct
4 Correct 119 ms 391656 KB Output is correct
5 Correct 424 ms 404600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 391764 KB Output is correct
2 Correct 529 ms 410744 KB Output is correct
3 Runtime error 489 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 391764 KB Output is correct
2 Correct 529 ms 410744 KB Output is correct
3 Runtime error 489 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 391764 KB Output is correct
2 Correct 529 ms 410744 KB Output is correct
3 Runtime error 489 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 391748 KB Output is correct
2 Correct 182 ms 391556 KB Output is correct
3 Correct 200 ms 391760 KB Output is correct
4 Runtime error 452 ms 524288 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 175 ms 391596 KB Output is correct
2 Correct 127 ms 392112 KB Output is correct
3 Correct 127 ms 392160 KB Output is correct
4 Correct 122 ms 391852 KB Output is correct
5 Correct 119 ms 391564 KB Output is correct
6 Correct 121 ms 391668 KB Output is correct
7 Correct 124 ms 391812 KB Output is correct
8 Correct 121 ms 391804 KB Output is correct
9 Correct 119 ms 391580 KB Output is correct
10 Correct 118 ms 391664 KB Output is correct
11 Correct 126 ms 391628 KB Output is correct
12 Correct 133 ms 391652 KB Output is correct
13 Correct 120 ms 391740 KB Output is correct
14 Correct 125 ms 391664 KB Output is correct
15 Correct 120 ms 391636 KB Output is correct
16 Correct 124 ms 392108 KB Output is correct
17 Correct 160 ms 393832 KB Output is correct
18 Correct 131 ms 391836 KB Output is correct
19 Correct 120 ms 391640 KB Output is correct
20 Correct 119 ms 391784 KB Output is correct
21 Correct 119 ms 391760 KB Output is correct
22 Correct 123 ms 391868 KB Output is correct
23 Correct 118 ms 391744 KB Output is correct
24 Correct 121 ms 391764 KB Output is correct
25 Correct 120 ms 391616 KB Output is correct
26 Correct 121 ms 391628 KB Output is correct
27 Correct 119 ms 391656 KB Output is correct
28 Correct 424 ms 404600 KB Output is correct
29 Correct 123 ms 391764 KB Output is correct
30 Correct 529 ms 410744 KB Output is correct
31 Runtime error 489 ms 524288 KB Execution killed with signal 9
32 Halted 0 ms 0 KB -