#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define sz(v) (int)v.size()
#define fi first
#define se second
#define INF 1223372036854775807
#define INF2 122337203
#define MOD 1000000007
#define cint(x) int x;cin>>x;
#define cinarr(a,n) int a[n];for (int i=0;i<n;i++) cin>>a[i];
#define coutarr(a) for (auto d:a)cout<<d<<" "; cout<<endl;
#define coutarrD(a) for (auto d:a) cout<<d.fi<<","<<d.se<<" "; cout<<endl;
#define BERKAY_TUP ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define ld long double
#define mid (start+end)/2
#define vvi vector<vector<int>>
int t=1;
int interactive=0;
int usaco=0;
int testCase=0;
vector<int> lll;
vector<int> rr;
vector<int> sm;
vector<int> lazy;
int c=2;
void push(int n,int start,int end){
if (lazy[n]){
lazy[lll[n]]=1;
lazy[rr[n]]=1;
sm[lll[n]]=mid-start+1;
sm[rr[n]]=end-mid;
}
}
void update(int n,int start,int end,int l,int r){
if (start>end || start>r || end<l) return;
if (start>=l && end<=r){
lazy[n]=1;
sm[n]=(end-start+1);
return;
}
if (lll[n]==0){
lll.pb(0);rr.pb(0);sm.pb(0);lazy.pb(0);
lll[n]=c;
c++;
}
if (rr[n]==0){
lll.pb(0);rr.pb(0);sm.pb(0);lazy.pb(0);
rr[n]=c;
c++;
}
push(n,start,end);
update(lll[n],start,mid,l,r);
update(rr[n],mid+1,end,l,r);
sm[n]=sm[lll[n]]+sm[rr[n]];
}
void solve(){
lll.pb(0);rr.pb(0);sm.pb(0);lazy.pb(0);
lll.pb(0);rr.pb(0);sm.pb(0);lazy.pb(0);
int n,a,b;
cin>>n>>a>>b;
int x;
if (a>INF/b) x=INF;
else x=a*b;
for (int i=0;i<n;i++){
int l,r;
cin>>l>>r;
if (l+x<=r){
cout<<x<<endl;
return;
}
else if (l%x+1<=r%x+1){
update(1,1,x,l%x+1,r%x+1);
}
else{
update(1,1,x,1,r%x+1);
update(1,1,x,l%x+1,x);
}
}
cout<<sm[1]<<endl;
}
int32_t main(){
BERKAY_TUP;
if (usaco){
freopen("team.in", "r", stdin);
freopen("team.out", "w", stdout);
}
if (!interactive){
#ifdef Local
freopen("in.txt", "r", stdin);
freopen("out2.txt", "w", stdout);
//freopen("wormsort.out", "w", stdout);
#endif
}
if (t==1) solve();
else{
cin>>t;
while (t--){testCase++;solve();}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:114:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
114 | freopen("team.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:115:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
115 | freopen("team.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |