Submission #249948

#TimeUsernameProblemLanguageResultExecution timeMemory
249948jeqchoStrange Device (APIO19_strange_device)C++17
0 / 100
535 ms16848 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<pair<int,int>> vpi; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define pb push_back #define rsz resize #define sz(x) int(x.size()) #define all(x) begin(x), end(x) #define f first #define s second int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; ll A,B; cin>>n>>A>>B; vector<pair<ll,ll>> segments; ll l,r; bool wrap; while(n--) { cin>>l>>r; if(r-l+1>A) { cout<<A+1<<'\n'; return 0; } if(r>l)wrap=1; else wrap=0; l *= 2; l %= A; r *= 2; r %= A; if(wrap&&r<=l) { segments.pb({0,l}); segments.pb({r,A-1}); } else segments.pb({l,r}); } sort(all(segments)); ll ldex,rdex; ll ans=0; segments.pb({4e18,0}); bool init=0; ll len; trav(seg,segments) { if(!init) { ldex=seg.f; rdex=seg.s; init=1; continue; } if(seg.f>rdex) { len = rdex-ldex+1; if(len&1) { if(rdex&1) { ans += len/2; } else ans += len/2 + 1; } else ans += len/2; ldex=seg.f; rdex=seg.s; } else { rdex = max(rdex,seg.s); } } cout<<ans<<'\n'; 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...