Submission #210207

#TimeUsernameProblemLanguageResultExecution timeMemory
210207tatyamStrange Device (APIO19_strange_device)C++17
100 / 100
775 ms33756 KiB
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; #define rep(n) for(int i=0;i<n;++i) #define all(i) begin(i),end(i) #define Sort(a) sort(all(a)) #define Rev(a) reverse(all(a)) using u128 = __uint128_t; signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ull n, a, b; cin >> n >> a >> b; u128 mod = a / gcd(a, b + 1) * u128(b); vector<pair<ull, int>> query; rep(n){ ull l, r; cin >> l >> r; if(r - l + 1 >= mod){ cout << ull(mod) << endl; return 0; } l %= mod; r %= mod; r++; query.emplace_back(l, 1); query.emplace_back(r, -1); if(l > r){ query.emplace_back(mod, -1); query.emplace_back(0, 1); } } Sort(query); Rev(query); ull at = 0, cnt = 0, ans = 0; while(query.size()){ ull next = query.back().first; if(cnt) ans += next - at; at = next; while(query.size() && query.back().first == at){ cnt += query.back().second; query.pop_back(); } } cout << ans << endl; }

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:4:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(n) for(int i=0;i<n;++i)
                            ~^~~~~~~~
 #define all(i) begin(i),end(i)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 #define Sort(a) sort(all(a))
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 #define Rev(a) reverse(all(a))
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 ~                            
 
 ~                            
 
 ~                            
 using u128 = __uint128_t;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~   
 signed main(){
 ~~~~~~~~~~~~~~~              
     cin.tie(nullptr);
     ~~~~~~~~~~~~~~~~~~       
     ios::sync_with_stdio(false);
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     ull n, a, b;
     ~~~~~~~~~~~~~            
     cin >> n >> a >> b;
     ~~~~~~~~~~~~~~~~~~~~     
     u128 mod = a / gcd(a, b + 1) * u128(b);
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     vector<pair<ull, int>> query;
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     rep(n){
     ~~~~~                    
strange_device.cpp:19:5: note: in expansion of macro 'rep'
     rep(n){
     ^~~
#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...