Submission #774092

#TimeUsernameProblemLanguageResultExecution timeMemory
774092RecursiveCoSnowball (JOI21_ho_t2)C++14
100 / 100
979 ms14004 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 signed main() { improvePerformance; get(n); get(q); getList(n, pos); getList(q, days); vector<pair<int, int>> segs; int pref = 0; forto(q, i) { pref += days[i]; if (i == 0) { if (days[i] > 0) segs.push_back({0, days[i]}); else segs.push_back({days[i], 0}); } else { if (days[i] > 0) segs.push_back({segs.back().first, max(segs.back().second, pref)}); else segs.push_back({min(segs.back().first, pref), segs.back().second}); } } forto(n, i) pos[i] += 1e12; forto(n, i) { int left = 0; int right = 0; if (i == 0) { left = -segs.back().first; } else { int l = pos[i - 1]; int r = pos[i]; while (r - l >= 1) { int middle = (l + r) / 2; // was middle already taken by the time we wanted to take it? int l1 = 0; int r1 = q; while (r1 - l1 >= 1) { int middle1 = (l1 + r1) / 2; if (segs[middle1].first + pos[i] <= middle) r1 = middle1; else l1 = middle1 + 1; } if (r1 == q) { l = middle + 1; continue; } if (segs[r1].second + pos[i - 1] > middle) l = middle + 1; else r = middle; } left = pos[i] - l; } if (i == n - 1) { right = segs.back().second; } else { int l = pos[i]; int r = pos[i + 1] + 1; while (r - l > 1) { int middle = (l + r) / 2; // was middle already taken by the time we wanted to take it? int l1 = 0; int r1 = q; while (r1 - l1 >= 1) { int middle1 = (l1 + r1) / 2; if (middle <= pos[i] + segs[middle1].second) r1 = middle1; else l1 = middle1 + 1; } if (r1 == q) { r = middle; continue; } if (segs[r1].first + pos[i + 1] < middle) r = middle; else l = middle; } right = l - pos[i]; } out(left + right); out("\n"); } }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:10:23: warning: unnecessary parentheses in declaration of 'n' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
Main.cpp:22:5: note: in expansion of macro 'get'
   22 |     get(n);
      |     ^~~
Main.cpp:10:23: warning: unnecessary parentheses in declaration of 'q' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
Main.cpp:23:5: note: in expansion of macro 'get'
   23 |     get(q);
      |     ^~~
Main.cpp:12:40: warning: unnecessary parentheses in declaration of 'pos' [-Wparentheses]
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                        ^
Main.cpp:24:5: note: in expansion of macro 'getList'
   24 |     getList(n, pos);
      |     ^~~~~~~
Main.cpp:10:23: warning: unnecessary parentheses in declaration of 'a' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
Main.cpp:12:76: note: in expansion of macro 'get'
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                                                            ^~~
Main.cpp:24:5: note: in expansion of macro 'getList'
   24 |     getList(n, pos);
      |     ^~~~~~~
Main.cpp:12:40: warning: unnecessary parentheses in declaration of 'days' [-Wparentheses]
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                        ^
Main.cpp:25:5: note: in expansion of macro 'getList'
   25 |     getList(q, days);
      |     ^~~~~~~
Main.cpp:10:23: warning: unnecessary parentheses in declaration of 'a' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
Main.cpp:12:76: note: in expansion of macro 'get'
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                                                            ^~~
Main.cpp:25:5: note: in expansion of macro 'getList'
   25 |     getList(q, days);
      |     ^~~~~~~
Main.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
Main.cpp:28:5: note: in expansion of macro 'forto'
   28 |     forto(q, i) {
      |     ^~~~~
Main.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
Main.cpp:38:5: note: in expansion of macro 'forto'
   38 |     forto(n, i) pos[i] += 1e12;
      |     ^~~~~
Main.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
Main.cpp:39:5: note: in expansion of macro 'forto'
   39 |     forto(n, i) {
      |     ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...