Submission #932930

#TimeUsernameProblemLanguageResultExecution timeMemory
93293012345678Strange Device (APIO19_strange_device)C++17
35 / 100
583 ms78768 KiB
#include <bits/stdc++.h> using namespace std; #define ll unsigned long long const int nx=1e6+5; ll n, a, b, l[nx], r[nx], sm, p, mx, res, tmp; set<pair<ll, ll>> s; void add_range(ll x, ll y) { x=x%p; y=y%p; if (y<x) y+=p; s.insert({x, min(p-1, y)}); if (y>=p) s.insert({0, y-p}); } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>a>>b; for (int i=1; i<=n; i++) cin>>l[i]>>r[i], mx=max(mx, r[i]-l[i]+1), sm+=(r[i]-l[i]+1); tmp=a/__gcd(a, b+1); if (tmp >= LLONG_MAX/b) return sm, 0; p=tmp*b; if (mx>=p) return cout<<p, 0; for (int i=1; i<=n; i++) add_range(l[i], r[i]); //for (auto [x, y]:s) cout<<"val "<<x<<' '<<y<<'\n'; for (auto itr=s.begin(); itr!=s.end()&&next(itr)!=s.end();) { auto itr2=next(itr); pair<ll, ll> nw; if (itr2->first>itr->second+1) itr=itr2; else nw={itr->first, max(itr->second, itr2->second)}, s.erase(itr), s.erase(itr2), s.insert(nw), itr=s.find(nw); } for (auto [x, y]:s) res+=y-x+1; cout<<res; } /* 3 5 10 1 20 50 68 89 98 */

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   24 |     for (int i=1; i<=n; i++) cin>>l[i]>>r[i], mx=max(mx, r[i]-l[i]+1), sm+=(r[i]-l[i]+1);
      |                   ~^~~
strange_device.cpp:26:36: warning: left operand of comma operator has no effect [-Wunused-value]
   26 |     if (tmp >= LLONG_MAX/b) return sm, 0;
      |                                    ^~
strange_device.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   29 |     for (int i=1; i<=n; i++) add_range(l[i], r[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...