Submission #1185196

#TimeUsernameProblemLanguageResultExecution timeMemory
1185196Zbyszek99Gift Exchange (JOI24_ho_t4)C++20
50 / 100
2597 ms19048 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define ull unsigned long long #define ff first #define ss second #define pii pair<int,int> #define pll pair<long long, long long> #define vi vector<int> #define vl vector<long long> #define pb push_back #define rep(i, b) for(int i = 0; i < (b); ++i) #define rep2(i,a,b) for(int i = a; i <= (b); ++i) #define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c) #define count_bits(x) __builtin_popcountll((x)) #define all(x) (x).begin(),(x).end() #define siz(x) (int)(x).size() #define forall(it,x) for(auto& it:(x)) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; //mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());} //ll los(ll a, ll b) {return a + (mt() % (b-a+1));} const int INF = 1e9+50; const ll INF_L = 1e18+40; const ll MOD = 1e9+7; const int tree_siz = 1024*2048-1; int drzewo1[tree_siz+1]; int get_max1(int akt, int p1, int p2, int s1, int s2) { if(p2 < s1 || p1 > s2) return 0; if(p1 >= s1 && p2 <= s2) return drzewo1[akt]; return max(get_max1(akt*2,p1,(p1+p2)/2,s1,s2),get_max1(akt*2+1,(p1+p2)/2+1,p2,s1,s2)); } void upd1(int v) { drzewo1[v] = max(drzewo1[v*2],drzewo1[v*2+1]); if(v != 1) upd1(v/2); } void change1(int ind, int v) { drzewo1[tree_siz/2+ind+1] = v; upd1((tree_siz/2+1+ind)/2); } int drzewo2[tree_siz+1]; void set_max2(int akt, int p1, int p2, int s1, int s2, int w) { if(p2 < s1 || p1 > s2) return; if(p1 >= s1 && p2 <= s2) { drzewo2[akt] = max(drzewo2[akt],w); return; } set_max2(akt*2,p1,(p1+p2)/2,s1,s2,w); set_max2(akt*2+1,(p1+p2)/2+1,p2,s1,s2,w); } int get_max2(int v) { return max(drzewo2[v],(v != 1 ? get_max2(v/2) : 0)); } int A[500'001]; int B[500'001]; int nxt_ok[500'001][2]; void calc_nxt(int n, int type) { rep2(i,1,tree_siz) { drzewo1[i] = 0; drzewo2[i] = 0; } rep2(i,1,n) { int prv = max(get_max2(tree_siz/2+1+A[i]),get_max1(1,0,tree_siz/2,B[i],A[i])); if(type == 0) nxt_ok[i][0] = prv; else nxt_ok[n-i+1][1] = n-prv+1; change1(A[i],i); set_max2(1,0,tree_siz/2,B[i],A[i],i); } } void query(int l, int r) { rep2(i,l,r) { if(!(nxt_ok[i][0] >= l || nxt_ok[i][1] <= r)) { cout << "No\n"; return; } } cout << "Yes\n"; } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //random_start(); int n; cin >> n; rep2(i,1,n) cin >> A[i]; rep2(i,1,n) cin >> B[i]; calc_nxt(n,0); reverse(A+1,A+n+1); reverse(B+1,B+n+1); calc_nxt(n,1); reverse(A+1,A+n+1); reverse(B+1,B+n+1); int q; cin >> q; rep(qq,q) { int l,r; cin >> l >> r; query(l,r); } }
#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...