이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
void solve(){
ll n,a,b; cin >> n >> a >> b;
vector<pair<ll,ll>> arr(n);
ll curr=0;
for(int i=0; i < n;i++){
cin >> arr[i].first >> arr[i].second;
curr+=arr[i].second - arr[i].first +1;
}
ll x=a/(__gcd(b+1,a));
ll maxi=x*b;
if((arr[n-1].second-1)< maxi){
cout << curr << endl;
return;
}
vector<pair<ll,ll>> ans;
for(int i=0; i < n;i++){
if(arr[i].second - arr[i].first +1>=maxi){
cout << maxi << endl;
return;
}
arr[i].second%=maxi;
arr[i].first%=maxi;
if(arr[i].first > arr[i].second){
ans.push_back({arr[i].first,maxi-1ll});
ans.push_back({0ll,arr[i].second});
} else{
ans.push_back({arr[i].first, arr[i].second});
}
}
sort(ans.begin(),ans.end());
vector<pair<ll,ll>> add;
curr=-1;
for(auto c: ans){
if(curr==-1){
curr=0;
add.push_back(c);
} else if(c.first > add[curr].second){
add.push_back(c);
curr++;
} else{
add[curr].second=max(add[curr].second,c.second);
}
}
ll out=0;
for(auto c : add) out += c.second - c.first +1;
cout << out << endl;
}
int main(){
ios::sync_with_stdio(false);cout.tie();cin.tie();
int t=1;
// cin >> t;
while(t--){
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
strange_device.cpp: In function 'void solve()':
strange_device.cpp:9:20: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
9 | for(int i=0; i < n;i++){
| ~~^~~
strange_device.cpp:20:20: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
20 | for(int i=0; i < n;i++){
| ~~^~~
strange_device.cpp:38:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
38 | if(curr==-1){
| ~~~~^~~~
# | 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... |