Submission #1092722

#TimeUsernameProblemLanguageResultExecution timeMemory
1092722I_am_Polish_GirlSnowball (JOI21_ho_t2)C++14
33 / 100
91 ms11448 KiB
#pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #pragma GCC optimization ("unroll-loops") #include <vector> #include <algorithm> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <stack> #include <queue> #include <cmath> #include <random> #include <chrono> #include <iomanip> #include <iostream> #include <bitset> #define int long long using namespace std; int log_ = 3; int inf = 200000000000000; int mod = 5; int p = 505; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n , m; cin >> n >> m; vector <int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector <int> pr; pr.push_back(0); int p = 0; for (int i = 0; i < m; i++) { int x; cin >> x; p += x; pr.push_back(p); } int mx = 0; int mn = 0; vector <int> pr2; pr2.push_back(0); for (int i = 1; i <= m; i++) { if (mn > pr[i]) { if (i + 1 <= m) { if (pr[i] > pr[i + 1]) continue; } pr2.push_back(pr[i]); mn = pr[i]; } if (mx < pr[i]) { if (i + 1 <= m) { if (pr[i] < pr[i + 1]) continue; } pr2.push_back(pr[i]); mx = pr[i]; } } pr = pr2; vector <int> l(pr.size(), 0); vector <int> r(pr.size() , 0); for (int i = 1; i < pr.size(); i++) { l[i] = min(l[i - 1], pr[i]); r[i] = max(r[i - 1], pr[i]); } for (int i = 0; i < n; i++) { int pr_ = -inf; if (i > 0) pr_ = a[i - 1]; int lx = 0; int rx = pr.size(); while (rx - lx > 1) { int m = (lx + rx) / 2; if ((-l[m] + r[m]) <= (a[i] - pr_)) { lx = m; } else rx = m; } int ans = 0; ans += -l[lx]; if (lx + 1 < l.size()) { if (l[lx] > l[lx + 1]) { ans += (a[i] - pr_) - (-l[lx] + r[lx]); } } int next_ = inf; if (i + 1 < n) next_ = a[i + 1]; lx = 0; rx = pr.size(); while (rx - lx > 1) { int m = (lx + rx) / 2; if ((-l[m] + r[m]) <= (next_ - a[i])) { lx = m; } else rx = m; } ans += r[lx]; if (lx + 1 < r.size()) { if (r[lx] < r[lx + 1]) { ans += (next_ - a[i]) - (-l[lx] + r[lx]); } } cout << ans << "\n"; } }

Compilation message (stderr)

Main.cpp:4: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    4 | #pragma GCC optimization ("unroll-loops")
      | 
Main.cpp: In function 'int main()':
Main.cpp:106:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |     for (int i = 1; i < pr.size(); i++)
      |                     ~~^~~~~~~~~~~
Main.cpp:138:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  138 |         if (lx + 1 < l.size())
      |             ~~~~~~~^~~~~~~~~~
Main.cpp:173:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  173 |         if (lx + 1 < r.size())
      |             ~~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...