Submission #568786

#TimeUsernameProblemLanguageResultExecution timeMemory
568786errorgornFish 2 (JOI22_fish2)C++17
25 / 100
4078 ms6604 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ii pair<int,int> #define fi first #define se second #define endl '\n' #define puf push_front #define pof pop_front #define pub push_back #define pob pop_back #define lb lower_bound #define ub upper_bound #define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--) #define all(x) (x).begin(),(x).end() #define sz(x) (int) (x).size() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n,q; int arr[100005]; vector<int> al[100005]; ii dfs(int i){ int tot=arr[i]; int num=1; for (auto it:al[i]){ auto temp=dfs(it); if (temp.fi>=arr[i]) num+=temp.se; tot+=temp.fi; } return {tot,num}; } int solve(int i,int j){ rep(x,i,j+1) al[x].clear(); vector<int> stk; rep(x,i,j+1){ while (!stk.empty() && arr[stk.back()]<=arr[x]){ int temp=stk.back(); stk.pob(); if (stk.empty() || arr[stk.back()]>arr[x]) al[x].pub(temp); else al[stk.back()].pub(temp); } stk.pub(x); } while (sz(stk)>=2){ int temp=stk.back(); stk.pob(); al[stk.back()].pub(temp); } return dfs(stk.back()).se; } signed main(){ cin.tie(0); cout.tie(0); cin.sync_with_stdio(false); cin>>n; rep(x,1,n+1) cin>>arr[x]; cin>>q; int a,b; rep(x,0,q){ cin>>a; if (a==1){ cin>>a>>b; arr[a]=b; } else{ cin>>a>>b; cout<<solve(a,b)<<endl; } } }
#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...