Submission #558843

#TimeUsernameProblemLanguageResultExecution timeMemory
558843myrcellaStrange Device (APIO19_strange_device)C++17
100 / 100
530 ms48652 KiB
//by szh #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pii pair<int,int> #define pll pair<long long,long long> #define pb push_back #define debug(x) cerr<<#x<<"="<<x<<endl #define pq priority_queue #define inf 0x3f #define rep(i,a,b) for (int i=a;i<(b);i++) #define MP make_pair #define SZ(x) (int(x.size())) #define ll long long #define ALL(x) x.begin(),x.end() const ll big = 1000000000000000000; ll mod; int n; ll a,b; vector <pll> range; int main() { // freopen("input.txt","r",stdin); std::ios::sync_with_stdio(false);cin.tie(); cin>>n>>a>>b; ll tmp = __gcd(a,b+1); tmp = a/tmp; if (1.0*big/tmp<(double)b) mod = big; else mod = b*tmp; debug(mod); rep(i,0,n) { ll l,r;cin>>l>>r; if (l/mod==r/mod) range.pb({l%mod,r%mod}); else range.pb({l%mod,mod-1}),range.pb({0,r%mod}); } sort(ALL(range)); ll cur = -1,ans=0; for (auto x:range) { if (x.fi<=cur) ans+=max(0ll,x.se-cur),cur = max(cur,x.se); else ans+=x.se-x.fi+1,cur = x.se; } cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...