Submission #951254

#TimeUsernameProblemLanguageResultExecution timeMemory
951254quanlt206Xylophone (JOI18_xylophone)C++17
0 / 100
1 ms344 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(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; } a[pos_1] = 1; if (pos_1 > 1) { a[pos_1 - 1] = query(pos_1 - 1, pos_1) + 1; int last_value = a[pos_1 - 1] - 1; int i = pos_1 - 1, mask = 0, top = pos_1; // mask = 0 : tang, 1 : giam while (i > 1) { int cur_value = query(i - 1, top); if (cur_value > last_value) { last_value = cur_value; if (mask == 0) a[i - 1] = a[top] + cur_value; else a[i - 1] = a[top] - cur_value; i--; continue; } if (mask == 0) { // dang la day tang dan cur_value = query(i - 1, i); last_value = cur_value; top = i; a[i - 1] = a[top] - cur_value; mask = 1; } else { cur_value = query(i - 1, i); last_value = cur_value; top = i; a[i - 1] = a[top] + cur_value; mask = 0; } i--; } } if (pos_1 < n) { a[pos_1 + 1] = query(pos_1, pos_1 + 1) + 1; int last_value = a[pos_1 + 1] - 1; int i = pos_1 + 1, mask = 0, top = pos_1; while (i < n) { int cur_value = query(top, i + 1); if (cur_value > last_value) { last_value = cur_value; if (mask == 0) a[i + 1] = a[top] + cur_value; else a[i + 1] = a[top] - cur_value; i++; continue; } if (mask == 0) { // dang la day tang dan cur_value = query(i, i + 1); last_value = cur_value; top = i; a[i + 1] = a[top] - cur_value; mask = 1; } else { cur_value = query(i, i + 1); last_value = cur_value; top = i; a[i + 1] = a[top] + cur_value; mask = 0; } i++; } } FOR(i, 1, n) answer(i, a[i]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...