이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
int main(){
std::ios::sync_with_stdio(0);
std::cin.tie(0);
int n,q;
std::cin>>n;
std::vector<int> vec;
for(int i=0;i<n;i++){
int x;
std::cin>>x;
vec.push_back(x);
}
std::cin>>q;
for(;q--;){
int a;
std::cin>>a;
if(a==1){
int b,c;
std::cin>>b>>c;
b--;
vec[b]=c;
}else{
int b,c;
std::cin>>b>>c;
b--;
std::vector<long long> sums;
std::vector<std::pair<long long,std::pair<long long,int>>> stk;//size of fish to the right, sum, number which can win
for(int i=b;i<c;i++){
stk.push_back({0,{0,0}});//for merging
while(stk.size()>=2&&stk[stk.size()-2].first<vec[i]){
//std::cout<<"m!\n";
if(stk.back().second.first>=stk[stk.size()-2].first){
stk[stk.size()-2].second.second+=stk.back().second.second;
}
stk[stk.size()-2].second.first+=stk.back().second.first;//add sum
stk.pop_back();
}
stk.back().first=vec[i];
stk.back().second.second=stk.back().second.first>=vec[i]?stk.back().second.second+1:1;
stk.back().second.first+=vec[i];
}
while(stk.size()>=2){
//std::cout<<"m\m";
if(stk.back().second.first>=stk[stk.size()-2].first){
stk[stk.size()-2].second.second+=stk.back().second.second;
}
stk[stk.size()-2].second.first+=stk.back().second.first;//add sum
stk.pop_back();
}
std::cout<<stk.back().second.second<<'\n';
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |