Untitled
unknown
c_cpp
7 months ago
1.3 kB
4
Indexable
#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define LSB(i) ((i) & (-i))
#define ll long long
const int dx[]{-1,1,0,0,-1,-1,1,1};
const int dy[]{0,0,1,-1,-1,1,-1,1};
const int MOD = 1e9+7;
#define int ll
const int N = 1e5+5;
void solve(int testCase) {
int n;
cin >> n;
std::vector<int> pre(n), a;
vector<array<int,2>> b;
for(int i = 0; i < n; ++i){
int x, val;
cin >> x;
if(x == 1) a.push_back(i);
else if(x == 2){
cin >> val;
pre[i] = val;
} else {
cin >> val;
b.push_back({i, val});
}
}
for(int i = 1; i < n; ++i) pre[i] += pre[i-1];
vector<int> ans(b.size());
int i = 0, j = 0;
while(i < a.size() && j < b.size()){
if(b[j][0] < a[i]){
++j;
continue;
}
if(pre[b[j][0]] - pre[a[i]] >= b[j][1]){
++ans[j];
++i;
} else {
++j;
}
}
for(int x : ans) cout << x << '\n';
}
int32_t main(){
fastio();
int t = 1;
// cin >> t;
for(int i = 1; i <= t; ++i){
solve(i);
}
return 0;
}Editor is loading...
Leave a Comment