이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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';
}
컴파일 시 표준 에러 (stderr) 메시지
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |