Submission #995130

#TimeUsernameProblemLanguageResultExecution timeMemory
995130mrwangStrange Device (APIO19_strange_device)C++14
100 / 100
320 ms54056 KiB
#include<bits/stdc++.h> #define TASKNAME "codeforce" #define pb push_back #define pli pair<ll,ll> #define fi first #define se second #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); using namespace std; using ll=long long; const ll maxN=2e5; const ll inf=3e18; const ll mod=1e9+7; ll n,A,B; vector<pli>vec; void solve() { cin >> n >> A >> B; ll x=(A/__gcd(A,B+1))*B; bool ok=true; ll sum=0; for(int i=1;i<=n;i++) { ll l,r; cin >> l >> r; sum+=r-l+1; if((r-l+1)>=x) { ok=false; } l%=x; r%=x; if(l<=r) { vec.pb({l,r}); } else { vec.pb({l,x-1}); vec.pb({0,r}); } } ll cc=A/(__gcd(A,B+1)); if(inf/cc<B) { cout << sum; return; } if(ok==false) { cout << x; return; } sort(vec.begin(),vec.end()); ll s = 0, hi = -1; for(int i = 0; i < vec.size(); i++){ if(vec[i].fi > hi){ s += (vec[i].se - vec[i].fi + 1); hi = vec[i].se; } else { s+=max(0ll,vec[i].se-hi); hi=max(hi,vec[i].se); } } cout << s << "\n"; } int main() { fastio //freopen(TASKNAME".INP","r",stdin); //freopen(TASKNAME".OUT","w",stdout); solve(); }

Compilation message (stderr)

strange_device.cpp: In function 'void solve()':
strange_device.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i = 0; i < vec.size(); i++){
      |                    ~~^~~~~~~~~~~~
#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...