# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
370781 | cpp219 | Strange Device (APIO19_strange_device) | C++14 | 531 ms | 31932 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e6 + 3;
const ll inf = 1e9 + 7;
LL a[N];
ll n,A,B,q,total;
vector<LL> v;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>n>>A>>B; q = A/__gcd(B + 1,A); total = q * B;
for (ll i = 1;i <= n;i++){
cin>>a[i].fs>>a[i].sc;
a[i].fs %= total; a[i].sc %= total;
if (a[i].fs <= a[i].sc) v.push_back(a[i]);
else{
v.push_back({0,a[i].sc}); v.push_back({a[i].fs,total - 1});
}
}
sort(v.begin(),v.end());
ll mx = -inf,ans = 0;
for (auto i : v){
if (i.sc <= mx) continue;
if (i.fs > mx) ans += i.sc - i.fs + 1;
else ans += max(0ll,i.sc - mx);
mx = max(mx,i.sc);
}
cout<<ans;
}
Compilation message (stderr)
# | 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... |