Submission #795553

#TimeUsernameProblemLanguageResultExecution timeMemory
795553RecursiveCoStrange Device (APIO19_strange_device)C++14
100 / 100
564 ms69032 KiB
// CF template, version 3.0 #include <bits/stdc++.h> using namespace std; #define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0) #define getTest int t; cin >> t #define eachTest for (int _var=0;_var<t;_var++) #define get(name) int (name); cin >> (name) #define out(o) cout << (o) #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); } #define sortl(name) sort((name).begin(), (name).end()) #define rev(name) reverse((name).begin(), (name).end()) #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++) #define decision(b) if (b){out("YES");}else{out("NO");} #define int long long int int gcd(int a, int b) { int A = min(a, b); int B = max(a, b); if (A == 0) return B; return gcd(A, B % A); } signed main() { improvePerformance; //getTest; //eachTest { get(n); get(A); get(B); bool toobig = (1e18 + A - 1) / A <= B; // should be good enough, theoretically. vector<pair<int, int>> events; int large; if (!toobig) large = A * B / gcd(A, B + 1); forto(n, i) { get(l); get(r); if (!toobig) { if (r - l + 1 >= A * B) { out(large); return 0; } l %= large; r %= large; } events.push_back({l, -1}); events.push_back({r, 1}); if (r < l) { events.push_back({0, -1}); events.push_back({large - 1, 1}); } } int ans = 0; int last = -1; int m = events.size(); sortl(events); int balance = 0; forto(m, i) { balance -= events[i].second; if (last == -1 && balance > 0) { last = events[i].first; } else if (balance == 0) { ans += (events[i].first - last + 1); last = -1; } } out(ans); //} }

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:10:23: warning: unnecessary parentheses in declaration of 'n' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
strange_device.cpp:32:9: note: in expansion of macro 'get'
   32 |         get(n);
      |         ^~~
strange_device.cpp:10:23: warning: unnecessary parentheses in declaration of 'A' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
strange_device.cpp:33:9: note: in expansion of macro 'get'
   33 |         get(A);
      |         ^~~
strange_device.cpp:10:23: warning: unnecessary parentheses in declaration of 'B' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
strange_device.cpp:34:9: note: in expansion of macro 'get'
   34 |         get(B);
      |         ^~~
strange_device.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
strange_device.cpp:39:9: note: in expansion of macro 'forto'
   39 |         forto(n, i) {
      |         ^~~~~
strange_device.cpp:10:23: warning: unnecessary parentheses in declaration of 'l' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
strange_device.cpp:40:13: note: in expansion of macro 'get'
   40 |             get(l);
      |             ^~~
strange_device.cpp:10:23: warning: unnecessary parentheses in declaration of 'r' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
strange_device.cpp:41:13: note: in expansion of macro 'get'
   41 |             get(r);
      |             ^~~
strange_device.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
strange_device.cpp:62:9: note: in expansion of macro 'forto'
   62 |         forto(m, i) {
      |         ^~~~~
strange_device.cpp:54:41: warning: 'large' may be used uninitialized in this function [-Wmaybe-uninitialized]
   54 |                 events.push_back({large - 1, 1});
      |                                   ~~~~~~^~~
#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...