Submission #1017156

#TimeUsernameProblemLanguageResultExecution timeMemory
1017156CookieGift Exchange (JOI24_ho_t4)C++14
100 / 100
1194 ms138068 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; #define sz(a) (int)a.size() #define ALL(v) v.begin(), v.end() #define ALLR(v) v.rbegin(), v.rend() #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> #define mpp make_pair const ld PI = 3.14159265359, prec = 1e-9;; //using u128 = __uint128_t; const int cox[4] = {1, 0, -1, 0}; const int coy[4] = {0, -1, 0, 1}; const ll mod = 1e9 + 7, pr = 31; const int mxn = 1e6 + 5, mxs = 3e5 * 50, sq = 500, mxv = 2e6 + 1; const int max_iter = 8e4, global_iter = 15e5 + 5; //const int base = (1 <<18); const ll inf = 1e9 + 5, neg = -69420, inf2 = 1e14; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, q; struct ST{ int type; int st[4 * mxn + 1], lz[4 * mxn + 1]; void init(int _type){ type = _type; if(type == 0){ for(int i = 1; i <= 8 * n; i++){ st[i] = lz[i] = inf; } } } int no(){ if(type == 0)return(inf); return(0); } int comb(int a, int b){ if(type == 0)return(min(a, b)); else return(max(a, b)); } void pull(int nd){ st[nd] = comb(st[nd << 1], st[nd << 1 | 1]); } void go(int nd, int v){ st[nd] = comb(st[nd], v); lz[nd] = comb(lz[nd], v); } void push(int nd){ int &v = lz[nd]; go(nd << 1, v); go(nd << 1 | 1, v); } void upd(int nd, int l, int r, int ql, int qr, int v){ if(ql > r || qr < l)return; if(ql <= l && qr >= r){ go(nd, v); return; } int mid = (l + r) >> 1; push(nd); upd(nd << 1, l, mid, ql, qr, v); upd(nd << 1 | 1, mid + 1, r, ql, qr, v); pull(nd); } int get(int nd, int l, int r, int ql, int qr){ if(ql > r || qr < l)return(no()); if(ql <= l && qr >= r)return(st[nd]); int mid = (l + r) >> 1; push(nd); return(comb(get(nd << 1, l, mid, ql, qr), get(nd << 1 | 1, mid + 1, r, ql, qr))); } }; ST stmx, stmn; vt<int>events[mxn + 1]; vt<pii>queries[mxn + 1]; bool ans[mxn + 1]; int st[4 * mxn + 1], a[mxn + 1], b[mxn + 1], l[mxn + 1], r[mxn + 1]; void upd(int nd, int l, int r, int id, int v){ if(l == r){ st[nd] = v; return; } int mid = (l + r) >> 1; if(id <= mid)upd(nd << 1, l, mid, id, v); else upd(nd << 1 | 1, mid + 1, r, id, v); st[nd] = max(st[nd << 1], st[nd << 1 | 1]); } int get(int nd, int l, int r, int ql, int qr){ if(ql > r || qr < l)return(0); if(ql <= l && qr >= r)return(st[nd]); int mid = (l + r) >> 1; return(max(get(nd << 1, l, mid, ql, qr), get(nd << 1 | 1, mid + 1, r, ql, qr))); } void solve(){ cin >> n; stmx.init(1); stmn.init(0); for(int i = 1; i <= n; i++)cin >> a[i]; for(int i = 1; i <= n; i++)cin >> b[i]; for(int i = 1; i <= n; i++){ l[i] = stmx.get(1, 1, 2 * n, b[i], a[i]); stmx.upd(1, 1, 2 * n, b[i], a[i], i); if(l[i] != inf){ events[l[i]].pb(i); } } for(int i = n; i >= 1; i--){ r[i] = stmn.get(1, 1, 2 * n, b[i], a[i]); stmn.upd(1, 1, 2 * n, b[i], a[i], i); } cin >> q; for(int i = 0; i < q; i++){ int l, r; cin >> l >> r; queries[l].pb(mpp(r, i)); } for(int i = 1; i <= n; i++){ upd(1, 1, n, i, r[i]); } for(int i = n; i >= 1; i--){ for(auto j: events[i]){ upd(1, 1, n, j, 0); } for(auto [rq, idq]: queries[i]){ ans[idq] = (get(1, 1, n, i, rq) <= rq); } } for(int i = 0; i < q; i++){ cout << ((ans[i]) ? "Yes" : "No") << "\n"; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("KHONG.inp", "r", stdin); //freopen("KHONG.out", "w", stdout); int tt; tt = 1; while(tt--)solve(); return(0); }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:129:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  129 |         for(auto [rq, idq]: queries[i]){
      |                  ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...