Submission #951144

#TimeUsernameProblemLanguageResultExecution timeMemory
951144quanlt206Xylophone (JOI18_xylophone)C++17
47 / 100
54 ms1716 KiB
#include "xylophone.h" #include<bits/stdc++.h> #define X first #define Y second #define all(x) begin(x), end(x) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define FORD(i, b, a) for(int i = (b); i >= (a); i--) #define REP(i, a, b) for (int i = (a); i < (b); i++) #define mxx max_element #define mnn min_element #define SQR(x) (1LL * (x) * (x)) #define MASK(i) (1LL << (i)) #define Point Vector #define left Left #define right Right #define div Div using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ld; typedef pair<db, db> pdb; typedef pair<ld, ld> pld; typedef pair<int, int> pii; typedef pair<int, pii> piii; typedef pair<ll, ll> pll; typedef pair<ll, pll> plll; typedef pair<ll, int> pli; typedef pair<ll, pii> plii; template<class A, class B> bool maximize(A& x, B y) { if (x < y) return x = y, true; else return false; } template<class A, class B> bool minimize(A& x, B y) { if (x > y) return x = y, true; else return false; } /* END OF TEMPLATE */ const int N = 5007; int n, b[N], a[N]; int cntQuery = 0; int qr[N]; void solve_1(int l, int r, int val) { if (l >= r) return ; // a[r] == 0 : Min, 1 : Max if (val == 0) { qr[r] = 0; int i = r - 1; while (i >= l) { int tmp = query(i, r); a[i] = a[r] + tmp; int d = l, c = i, g, j; while (d <= c) { g = (d + c) >> 1; if (query(g, r) == tmp) j = g, c = g - 1; else d = g + 1; } i = j - 1; } i = r; while (i >= l) { int j = i; while (a[j - 1] == 0 && j > l) j--; solve_1(j, i, 1); i = j - 1; } } else { qr[r] = 0; int i = r - 1; while (i >= l) { int tmp = query(i, r); a[i] = a[r] - tmp; int d = l, c = i, g, j; while (d <= c) { g = (d + c) >> 1; if (query(g, r) == tmp) j = g, c = g - 1; else d = g + 1; } i = j - 1; } i = r; while (i >= l) { int j = i; while (a[j - 1] == 0 && j > l) j--; solve_1(j, i, 0); i = j - 1; } } } void solve_2(int l, int r, int val) { // a[l] == Min ? Max if (l >= r) return ; if (val == 0) { qr[l] = 0; int i = l + 1; while (i <= r) { int tmp = query(l, i); a[i] = a[l] + tmp; int d = i, c = r, g, j; while (d <= c) { g = (d + c) >> 1; if (query(l, g) == tmp) j = g, d = g + 1; else c = g - 1; } i = j + 1; } i = l; while (i <= r) { int j = i; while (a[j + 1] == 0 && j < r) j++; solve_2(i, j, 1); i = j + 1; } } else { qr[l] = 0; int i = l + 1; while (i <= r) { int tmp = query(l, i); a[i] = a[l] - tmp; int d = i, c = r, g, j = -1; while (d <= c) { g = (d + c) >> 1; if (query(l, g) == tmp) j = g, d = g + 1; else c = g - 1; } i = j + 1; } i = l; while (i <= r) { int j = i; while (a[j + 1] == 0 && j < r) j++; solve_2(i, j, 0); i = j + 1; } } } void solve(int m) { n = m; FOR(i, 1, n) a[i] = 0, qr[i] = 0; int pos_1 = 0; int d = 1, c = n, g; while (d <= c) { g = (d + c) >> 1; if (query(g, n) == n - 1) pos_1 = g, d = g + 1; else c = g - 1; } FOR(i, 1, n) { if (i != pos_1) qr[i] = query(min(i, pos_1), max(i, pos_1)); if (qr[i] == n - 1) break; } a[pos_1] = 1; qr[pos_1] = 0; FORD(i, pos_1 - 1, 1) if (qr[i] > qr[i + 1]) a[i] = qr[i] + 1; FOR(i, pos_1 + 1, n) if (qr[i] > qr[i - 1]) a[i] = qr[i] + 1; int i = pos_1; vector<pii> left, right; while (i > 0) { int j = i; while (j > 1 && a[j - 1] == 0) j--; left.push_back({j, i}); i = j - 1; } i = pos_1; while (i <= n) { int j = i; while (j < n && a[j + 1] == 0) j++; right.push_back({i, j}); i = j + 1; } for (auto x : left) solve_1(x.X, x.Y, 1); for (auto x : right) solve_2(x.X, x.Y, 1); FOR(i, 1, n) answer(i, a[i]); }

Compilation message (stderr)

xylophone.cpp: In function 'void solve_1(int, int, int)':
xylophone.cpp:86:15: warning: 'j' may be used uninitialized in this function [-Wmaybe-uninitialized]
   86 |             i = j - 1;
      |             ~~^~~~~~~
xylophone.cpp:65:15: warning: 'j' may be used uninitialized in this function [-Wmaybe-uninitialized]
   65 |             i = j - 1;
      |             ~~^~~~~~~
xylophone.cpp: In function 'void solve_2(int, int, int)':
xylophone.cpp:112:15: warning: 'j' may be used uninitialized in this function [-Wmaybe-uninitialized]
  112 |             i = j + 1;
      |             ~~^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...