Submission #1092751

#TimeUsernameProblemLanguageResultExecution timeMemory
1092751Saul0906Secret (JOI14_secret)C++14
100 / 100
317 ms4752 KiB
#include "secret.h" #include <bits/stdc++.h> #define pii pair<int,int> #define pll pair<ll,ll> #define fi first #define se second #define endl "\n" #define rep(a,b,c) for(ll a=b; a<c; a++) #define rep2(a,b,c,d) for(ll a=b; a<c; a+=d) #define repr(a,b,c) for(ll a=b-1; a>c-1; a--) #define repa(a,b) for(const auto &a: b) #define multicase() int t; cin>>t; while(t--) #define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define valid(c) cout<<(c ? "YES" : "NO")<<endl; #define valid2(c,a,b) cout<<(c ? a : b)<<endl; #define ll long long #define pq_min(a) priority_queue<a, vector<a>, greater<a>> #define pq_max(a) priority_queue<a> #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define mid ((l+r)>>1) #define flush endl<<flush #define vi vector<int> using namespace std; int n; vi a; struct segtree{ segtree *left, *right; int l, r; vi p, s; segtree(){} segtree(int x, int y): l(x), r(y){ if(l==r){ p.pb(a[l]); s.pb(a[l]); return; } left = new segtree(l,mid); right = new segtree(mid+1,r); if(x==0 && y==n-1) return; p.resize(r-l+1); s.resize(r-l+1); p[0]=left->p[0]; s[0]=Secret(left->p.back(),right->p.back()); s[r-l]=right->s.back(); p[r-l]=s[0]; rep(i,l+1,r){ if(i>mid){ p[i-l]=Secret(left->p.back(),right->p[i-mid-1]); s[i-l]=right->s[i-mid-1]; }else{ p[i-l]=left->p[i-l]; s[i-l]=Secret(left->s[i-l],right->p.back()); } } } int query(int x, int y){ if(x==y) return a[x]; if(y<l || r<x) return 0; if(x<=mid && y>mid){ return Secret(left->s[x-l],right->p[y-mid-1]); } return left->query(x,y)+right->query(x,y); } } st; void Init(int N, int A[]) { a.resize(N); n=N; rep(i,0,n) a[i]=A[i]; st = segtree(0,N-1); } int Query(int L, int R) { return st.query(L,R); }
#Verdict Execution timeMemoryGrader output
Fetching results...