Submission #648935

#TimeUsernameProblemLanguageResultExecution timeMemory
648935FEDIKUSStrange Device (APIO19_strange_device)C++17
100 / 100
2135 ms100160 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll n,a,b; cin>>n>>a>>b; ll period=-1; if(a/__gcd(a,b+1)>(1e18+10)/b+1) period=1e18+10; else period=a/__gcd(a,b+1)*b; map<ll,ll> ev; for(int i=0;i<n;i++){ ll l,r; cin>>l>>r; if(r-l+1>=period){ ev[0]++; ev[period]--; continue; } l%=period; r%=period; if(l<=r){ ev[l]++; ev[r+1]--; }else{ ev[0]++; ev[r+1]--; ev[l]++; ev[period]--; } } ll res=0; ll tren=0; ll prosli=-1; for(auto i:ev){ tren+=i.second; if(tren>0){ if(prosli==-1) prosli=i.first; }else{ if(res!=-1) res+=i.first-prosli; prosli=-1; } } cout<<res; 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...