Submission #486020

#TimeUsernameProblemLanguageResultExecution timeMemory
486020PoPularPlusPlusFire (JOI20_ho_t5)C++17
6 / 100
194 ms15728 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pb(e) push_back(e) #define sv(a) sort(a.begin(),a.end()) #define sa(a,n) sort(a,a+n) #define mp(a,b) make_pair(a,b) #define vf first #define vs second #define ar array #define all(x) x.begin(),x.end() const int inf = 0x3f3f3f3f; const int mod = 1000000007; const double PI=3.14159265358979323846264338327950288419716939937510582097494459230; bool remender(ll a , ll b){return a%b;} struct Seg { ll siz = 1; vector<ll> sums; void init(int n){ while(siz < n)siz*=2; sums.assign(siz * 2, 0LL); } void build(vector<ll>& arr , int x , int lx , int rx){ if(rx-lx==1){ if(lx < (int)arr.size()){ sums[x] = arr[lx]; } return; } int m = (lx + rx) / 2; build(arr , 2 * x + 1 , lx , m); build(arr, 2 * x + 2 , m , rx); sums[x] = sums[2 * x + 1] + sums[2 * x + 2]; } void build(vector<ll>& arr){ build(arr , 0 , 0 , siz); } void set(int i , int v , int x , int lx , int rx){ if(rx - lx ==1){ sums[x] = v; return; } int m = (lx + rx) / 2; if(i < m){ set(i , v , 2 * x + 1 , lx , m); } else { set(i , v , 2 * x + 2 , m , rx); } sums[x]=sums[2 * x + 1] + sums[2 * x + 2]; } void set(int x , int y){ set(x ,y , 0 , 0 , siz); } ll sum(int l , int r , int x , int lx , int rx){ if(lx >= l && rx <= r){ return sums[x]; } if(lx >= r || rx <= l)return 0; int m = (lx + rx) / 2; return sum(l , r , 2 * x + 1 , lx , m) + sum(l , r , 2 * x + 2 , m , rx); } ll sum(int l , int r){ return sum(l , r , 0 , 0 , siz); } }; void solve(){ int n,q; cin >> n >> q; vector<ll> arr(n); for(int i = 0; i < n; i++)cin >> arr[i]; Seg st; st.init(n + 5); st.build(arr); vector<int> v2; for(int i = 0; i < n-1; i++){ if(arr[i] == 2 && arr[i + 1] == 1)v2.pb(i + 1); } vector<pair<pair<int,int>,pair<int,int>>> v; for(int i = 0; i < q; i++){ int t , l , r; cin >> t >> l >> r; l--; r--; v.pb(mp(mp(t,i),mp(l,r))); } int ans[q]; sv(v); int j = 0; for(int time = 1; time <= n; time++){ for(int i : v2){ arr[i] = 2; st.set(i,2); } vector<int> v1; for(int i : v2){ if(i < n-1 && arr[i + 1] == 1)v1.pb(i + 1); } v2 = v1; while(j < q && v[j].vf.vf == time){ ans[v[j].vf.vs] = st.sum(v[j].vs.vf , v[j].vs.vs + 1); j++; } } for(int i = 0; i < q; i++){ cout << ans[i] << '\n'; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); //int t;cin >> t;while(t--) solve(); return 0; }
#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...