Submission #400066

#TimeUsernameProblemLanguageResultExecution timeMemory
400066juggernautStrange Device (APIO19_strange_device)C++17
100 / 100
542 ms30400 KiB
//Another code but understand that a*b/gcd(a,b+1) is all !!!! #include<bits/stdc++.h> using namespace std; #define int long long const int inf=1e18+69; vector<pair<int, int> >seg; int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, a, b; cin>>n>>a>>b; int gcd=__gcd(a, b+1); int t; if(a/gcd>inf/b) t=inf; //a*b/gcd>inf else t=(a/gcd)*b; for(int i=0; i<n; i++){ int l, r; cin>>l>>r; if(r-l+1>=t) seg.push_back({0, t-1}); else{ l%=t; r%=t; if(l<=r) seg.push_back({l, r}); else{ seg.push_back({l, t-1}); seg.push_back({0, r}); } } } sort(seg.begin(), seg.end()); int ans=0; for(int i=0; i<(int)seg.size(); i++){ int l=seg[i].first, r=seg[i].second; int nxt=i; while(nxt+1<seg.size()&&seg[nxt+1].first<=r){ r=max(r, seg[nxt+1].second); nxt++; } ans+=r-l+1; i=nxt; } cout<<ans<<endl; return 0; }

Compilation message (stderr)

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:33:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   while(nxt+1<seg.size()&&seg[nxt+1].first<=r){
      |         ~~~~~^~~~~~~~~~~
#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...