Submission #741581

#TimeUsernameProblemLanguageResultExecution timeMemory
741581maomao90Modern Machine (JOI23_ho_t5)C++17
25 / 100
3064 ms3724 KiB
// Hallelujah, praise the one who set me free // Hallelujah, death has lost its grip on me // You have broken every chain, There's salvation in your name // Jesus Christ, my living hope #include <bits/stdc++.h> using namespace std; #define REP(i, s, e) for (int i = (s); i < (e); i++) #define RREP(i, s, e) for (int i = (s); i >= (e); i--) template <class T> inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;} template <class T> inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;} typedef long long ll; typedef long double ld; #define FI first #define SE second typedef pair<int, int> ii; typedef pair<ll, ll> pll; typedef tuple<int, int, int> iii; #define ALL(_a) _a.begin(), _a.end() #define SZ(_a) (int) _a.size() #define pb push_back typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; typedef vector<iii> viii; #ifndef DEBUG #define cerr if (0) cerr #endif const int INF = 1000000005; const ll LINF = 1000000000000000005ll; const int MAXN = 120005; int n, m, q; bool c[MAXN]; int a[MAXN]; #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1 int sm[MAXN * 4], lz[MAXN * 4]; void init(int u = 1, int lo = 1, int hi = n) { lz[u] = -1; if (lo == hi) { sm[u] = c[lo]; cerr << u << ' ' << lo << ' ' << hi << ": " << sm[u] << '\n'; return; } MLR; init(lc, lo, mid); init(rc, mid + 1, hi); sm[u] = sm[lc] + sm[rc]; cerr << u << ' ' << lo << ' ' << hi << ": " << sm[u] << '\n'; } void propo(int u, int lo, int hi) { if (lz[u] == -1) { return; } MLR; sm[lc] = lz[u] * (mid - lo + 1); sm[rc] = lz[u] * (hi - mid); lz[lc] = lz[u]; lz[rc] = lz[u]; lz[u] = -1; } int qsm(int s, int e, int u = 1, int lo = 1, int hi = n) { if (s > e) { return 0; } if (lo >= s && hi <= e) { return sm[u]; } MLR; propo(u, lo, hi); int res = 0; if (s <= mid) { res += qsm(s, e, lc, lo, mid); } if (e > mid) { res += qsm(s, e, rc, mid + 1, hi); } return res; } void upd(int s, int e, int x, int u = 1, int lo = 1, int hi = n) { if (s > e) { return; } if (lo >= s && hi <= e) { sm[u] = x * (hi - lo + 1); lz[u] = x; return; } MLR; propo(u, lo, hi); if (s <= mid) { upd(s, e, x, lc, lo, mid); } if (e > mid) { upd(s, e, x, rc, mid + 1, hi); } sm[u] = sm[lc] + sm[rc]; } int lb(int x, bool inv, int u = 1, int lo = 1, int hi = n) { int usm = sm[u]; if (inv) { usm = hi - lo + 1 - sm[u]; } if (usm < x) { return INF; } if (lo == hi) { assert(usm == x); return lo; } MLR; propo(u, lo, hi); int lsm = sm[lc]; if (inv) { lsm = mid - lo + 1 - sm[lc]; } if (lsm >= x) { return lb(x, inv, lc, lo, mid); } else { return lb(x - lsm, inv, rc, mid + 1, hi); } } int main() { #ifndef DEBUG ios::sync_with_stdio(0), cin.tie(0); #endif cin >> n >> m; REP (i, 1, n + 1) { char t; cin >> t; c[i] = t == 'R'; } REP (i, 1, m + 1) { cin >> a[i]; } cin >> q; while (q--) { int l, r; cin >> l >> r; init(); REP (i, l, r + 1) { int p = a[i]; int lftr = qsm(1, p - 1), rhtb = n - p - qsm(p + 1, n); cerr << p << ' ' << lftr << ' ' << rhtb << '\n'; if (lftr < rhtb) { int lftb = p - qsm(1, p); int np = lb(lftb + lftr + 1, 1); upd(1, np, 1); } else { int rhtr = qsm(p, n); int tot = qsm(1, n); int np = lb(tot - rhtr - rhtb + 1, 0); cerr << ' ' << np << '\n'; upd(np, n, 0); } } cout << qsm(1, n) << '\n'; } return 0; }

Compilation message (stderr)

Main.cpp: In function 'void init(int, int, int)':
Main.cpp:42:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
      |                       ~~~^~~~
Main.cpp:51:5: note: in expansion of macro 'MLR'
   51 |     MLR;
      |     ^~~
Main.cpp: In function 'void propo(int, int, int)':
Main.cpp:42:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
      |                       ~~~^~~~
Main.cpp:61:5: note: in expansion of macro 'MLR'
   61 |     MLR;
      |     ^~~
Main.cpp: In function 'int qsm(int, int, int, int, int)':
Main.cpp:42:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
      |                       ~~~^~~~
Main.cpp:75:5: note: in expansion of macro 'MLR'
   75 |     MLR;
      |     ^~~
Main.cpp: In function 'void upd(int, int, int, int, int, int)':
Main.cpp:42:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
      |                       ~~~^~~~
Main.cpp:95:5: note: in expansion of macro 'MLR'
   95 |     MLR;
      |     ^~~
Main.cpp: In function 'int lb(int, bool, int, int, int)':
Main.cpp:42:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
      |                       ~~~^~~~
Main.cpp:117:5: note: in expansion of macro 'MLR'
  117 |     MLR;
      |     ^~~
#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...