#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
int n,m,q,ans[250005],base[250005];
ll s[1<<20],lz[1<<20],fen[250050];
struct Gr {
int val,idx,gr;
};
vector<pii> want[250005]; //number on queue and the index of ans
vector<Gr> p[250005]; //people, idx, group
vector<pii> qu[250005]; //queue, idx
ll find(int x) {
ll sum=0;
while (x) {
sum+=fen[x];
x-=x&-x;
}
return sum;
}
void upd(int x, ll val) {
while (x<=q+5) {
fen[x]+=val;
x+=x&-x;
}
}
void push(int l, int r, int idx) {
s[idx]+=lz[idx];
if (l!=r) {
lz[2*idx]+=lz[idx];
lz[2*idx+1]+=lz[idx];
}
lz[idx]=0;
}
void update(int l, int r, int idx, int x, int y, ll val) {
push(l,r,idx);
if (x>r || y<l) return;
if (x<=l && r<=y) {
lz[idx]+=val;
push(l,r,idx);
} else {
int mid=(l+r)/2;
update(l,mid,2*idx,x,y,val);
update(mid+1,r,2*idx+1,x,y,val);
s[idx]=min(s[2*idx],s[2*idx+1]);
}
}
ll query(int l, int r, int idx, int x, int y) {
push(l,r,idx);
if (x>r || y<l) return LLONG_MAX;
if (x<=l && r<=y) return s[idx];
int mid=(l+r)/2;
return min(query(l,mid,2*idx,x,y),query(mid+1,r,2*idx+1,x,y));
}
ll seg[1<<20]; //sum of people
void update2(int l, int r, int idx, int x, ll val) {
if (x>r || x<l) return;
if (l==r) seg[idx]=val;
else {
int mid=(l+r)/2;
update2(l,mid,2*idx,x,val);
update2(mid+1,r,2*idx+1,x,val);
seg[idx]=seg[2*idx]+seg[2*idx+1];
}
}
int query2(int l, int r, int idx, ll want) {
if (l==r) return l;
int mid=(l+r)/2;
if (seg[2*idx]>=want) return query2(l,mid,2*idx,want);
else return query2(mid+1,r,2*idx+1,want-seg[2*idx]);
}
int f(ll want, int d) {
if (seg[1]<want) return 0;
int h=query2(1,q,1,want);
if (h<=d) return h;
else return 0;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
memset(ans,-1,sizeof(ans));
memset(base,-1,sizeof(base));
base[0]=0;
cin>>n>>m>>q;
for (int i=1; i<=q; ++i) {
int mode; cin>>mode;
if (mode==1) {
int l,r,c,k; cin>>l>>r>>c>>k;
p[l].push_back({k,i,c});
p[r+1].push_back({-k,i,c});
} else if (mode==2) {
int l,r,k; cin>>l>>r>>k;
qu[l].push_back(pii(k,i));
qu[r+1].push_back(pii(-k,i));
} else {
int a,b; cin>>a>>b;
want[a].push_back(pii(b,i));
}
}
for (int i=1; i<=n; ++i) {
//add people
for (auto s : p[i]) {
update(1,q,1,s.idx,q,s.val);
upd(s.idx,s.val);
if (s.val>0) base[s.idx]=s.gr, update2(1,q,1,s.idx,s.val);
else base[s.idx]=-1, update2(1,q,1,s.idx,0);
}
//add bound of queue
for (auto s : qu[i]) update(1,q,1,s.second,q,-s.first);
//find real queue
for (auto s : want[i]) {
ll want=s.first+(find(s.second)-(query(1,q,1,s.second,s.second)-min(0ll,query(1,q,1,1,s.second))));
ans[s.second]=base[f(want,s.second)];
}
}
for (int i=1; i<=q; ++i) {
if (ans[i]!=-1) cout<<ans[i]<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
20056 KB |
Output is correct |
2 |
Correct |
13 ms |
20044 KB |
Output is correct |
3 |
Correct |
13 ms |
20048 KB |
Output is correct |
4 |
Correct |
13 ms |
20048 KB |
Output is correct |
5 |
Correct |
11 ms |
20052 KB |
Output is correct |
6 |
Correct |
10 ms |
20100 KB |
Output is correct |
7 |
Correct |
11 ms |
20136 KB |
Output is correct |
8 |
Correct |
12 ms |
20084 KB |
Output is correct |
9 |
Correct |
11 ms |
20052 KB |
Output is correct |
10 |
Correct |
12 ms |
20052 KB |
Output is correct |
11 |
Correct |
11 ms |
20164 KB |
Output is correct |
12 |
Correct |
12 ms |
20044 KB |
Output is correct |
13 |
Correct |
10 ms |
20052 KB |
Output is correct |
14 |
Correct |
11 ms |
20100 KB |
Output is correct |
15 |
Correct |
10 ms |
20044 KB |
Output is correct |
16 |
Correct |
12 ms |
20100 KB |
Output is correct |
17 |
Correct |
12 ms |
20052 KB |
Output is correct |
18 |
Correct |
12 ms |
20048 KB |
Output is correct |
19 |
Correct |
13 ms |
20052 KB |
Output is correct |
20 |
Correct |
12 ms |
20052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
20056 KB |
Output is correct |
2 |
Correct |
13 ms |
20044 KB |
Output is correct |
3 |
Correct |
13 ms |
20048 KB |
Output is correct |
4 |
Correct |
13 ms |
20048 KB |
Output is correct |
5 |
Correct |
11 ms |
20052 KB |
Output is correct |
6 |
Correct |
10 ms |
20100 KB |
Output is correct |
7 |
Correct |
11 ms |
20136 KB |
Output is correct |
8 |
Correct |
12 ms |
20084 KB |
Output is correct |
9 |
Correct |
11 ms |
20052 KB |
Output is correct |
10 |
Correct |
12 ms |
20052 KB |
Output is correct |
11 |
Correct |
11 ms |
20164 KB |
Output is correct |
12 |
Correct |
12 ms |
20044 KB |
Output is correct |
13 |
Correct |
10 ms |
20052 KB |
Output is correct |
14 |
Correct |
11 ms |
20100 KB |
Output is correct |
15 |
Correct |
10 ms |
20044 KB |
Output is correct |
16 |
Correct |
12 ms |
20100 KB |
Output is correct |
17 |
Correct |
12 ms |
20052 KB |
Output is correct |
18 |
Correct |
12 ms |
20048 KB |
Output is correct |
19 |
Correct |
13 ms |
20052 KB |
Output is correct |
20 |
Correct |
12 ms |
20052 KB |
Output is correct |
21 |
Incorrect |
10 ms |
20032 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
27560 KB |
Output is correct |
2 |
Correct |
92 ms |
27596 KB |
Output is correct |
3 |
Correct |
82 ms |
27572 KB |
Output is correct |
4 |
Correct |
82 ms |
27604 KB |
Output is correct |
5 |
Correct |
84 ms |
27596 KB |
Output is correct |
6 |
Correct |
109 ms |
27592 KB |
Output is correct |
7 |
Correct |
45 ms |
26056 KB |
Output is correct |
8 |
Correct |
48 ms |
25844 KB |
Output is correct |
9 |
Correct |
79 ms |
27176 KB |
Output is correct |
10 |
Correct |
101 ms |
27724 KB |
Output is correct |
11 |
Correct |
102 ms |
27528 KB |
Output is correct |
12 |
Correct |
80 ms |
27728 KB |
Output is correct |
13 |
Correct |
75 ms |
26744 KB |
Output is correct |
14 |
Correct |
89 ms |
27272 KB |
Output is correct |
15 |
Correct |
90 ms |
27216 KB |
Output is correct |
16 |
Correct |
102 ms |
27340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
123 ms |
32384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
20056 KB |
Output is correct |
2 |
Correct |
13 ms |
20044 KB |
Output is correct |
3 |
Correct |
13 ms |
20048 KB |
Output is correct |
4 |
Correct |
13 ms |
20048 KB |
Output is correct |
5 |
Correct |
11 ms |
20052 KB |
Output is correct |
6 |
Correct |
10 ms |
20100 KB |
Output is correct |
7 |
Correct |
11 ms |
20136 KB |
Output is correct |
8 |
Correct |
12 ms |
20084 KB |
Output is correct |
9 |
Correct |
11 ms |
20052 KB |
Output is correct |
10 |
Correct |
12 ms |
20052 KB |
Output is correct |
11 |
Correct |
11 ms |
20164 KB |
Output is correct |
12 |
Correct |
12 ms |
20044 KB |
Output is correct |
13 |
Correct |
10 ms |
20052 KB |
Output is correct |
14 |
Correct |
11 ms |
20100 KB |
Output is correct |
15 |
Correct |
10 ms |
20044 KB |
Output is correct |
16 |
Correct |
12 ms |
20100 KB |
Output is correct |
17 |
Correct |
12 ms |
20052 KB |
Output is correct |
18 |
Correct |
12 ms |
20048 KB |
Output is correct |
19 |
Correct |
13 ms |
20052 KB |
Output is correct |
20 |
Correct |
12 ms |
20052 KB |
Output is correct |
21 |
Correct |
80 ms |
27560 KB |
Output is correct |
22 |
Correct |
92 ms |
27596 KB |
Output is correct |
23 |
Correct |
82 ms |
27572 KB |
Output is correct |
24 |
Correct |
82 ms |
27604 KB |
Output is correct |
25 |
Correct |
84 ms |
27596 KB |
Output is correct |
26 |
Correct |
109 ms |
27592 KB |
Output is correct |
27 |
Correct |
45 ms |
26056 KB |
Output is correct |
28 |
Correct |
48 ms |
25844 KB |
Output is correct |
29 |
Correct |
79 ms |
27176 KB |
Output is correct |
30 |
Correct |
101 ms |
27724 KB |
Output is correct |
31 |
Correct |
102 ms |
27528 KB |
Output is correct |
32 |
Correct |
80 ms |
27728 KB |
Output is correct |
33 |
Correct |
75 ms |
26744 KB |
Output is correct |
34 |
Correct |
89 ms |
27272 KB |
Output is correct |
35 |
Correct |
90 ms |
27216 KB |
Output is correct |
36 |
Correct |
102 ms |
27340 KB |
Output is correct |
37 |
Correct |
79 ms |
26944 KB |
Output is correct |
38 |
Correct |
73 ms |
26572 KB |
Output is correct |
39 |
Correct |
39 ms |
25460 KB |
Output is correct |
40 |
Correct |
52 ms |
25964 KB |
Output is correct |
41 |
Correct |
84 ms |
26804 KB |
Output is correct |
42 |
Correct |
80 ms |
27596 KB |
Output is correct |
43 |
Correct |
83 ms |
27504 KB |
Output is correct |
44 |
Correct |
79 ms |
27164 KB |
Output is correct |
45 |
Correct |
86 ms |
27596 KB |
Output is correct |
46 |
Correct |
85 ms |
27508 KB |
Output is correct |
47 |
Correct |
54 ms |
26216 KB |
Output is correct |
48 |
Correct |
74 ms |
27196 KB |
Output is correct |
49 |
Correct |
63 ms |
26216 KB |
Output is correct |
50 |
Correct |
75 ms |
26920 KB |
Output is correct |
51 |
Correct |
82 ms |
27608 KB |
Output is correct |
52 |
Correct |
86 ms |
27568 KB |
Output is correct |
53 |
Correct |
94 ms |
26364 KB |
Output is correct |
54 |
Correct |
91 ms |
27340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
38 ms |
23384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
20056 KB |
Output is correct |
2 |
Correct |
13 ms |
20044 KB |
Output is correct |
3 |
Correct |
13 ms |
20048 KB |
Output is correct |
4 |
Correct |
13 ms |
20048 KB |
Output is correct |
5 |
Correct |
11 ms |
20052 KB |
Output is correct |
6 |
Correct |
10 ms |
20100 KB |
Output is correct |
7 |
Correct |
11 ms |
20136 KB |
Output is correct |
8 |
Correct |
12 ms |
20084 KB |
Output is correct |
9 |
Correct |
11 ms |
20052 KB |
Output is correct |
10 |
Correct |
12 ms |
20052 KB |
Output is correct |
11 |
Correct |
11 ms |
20164 KB |
Output is correct |
12 |
Correct |
12 ms |
20044 KB |
Output is correct |
13 |
Correct |
10 ms |
20052 KB |
Output is correct |
14 |
Correct |
11 ms |
20100 KB |
Output is correct |
15 |
Correct |
10 ms |
20044 KB |
Output is correct |
16 |
Correct |
12 ms |
20100 KB |
Output is correct |
17 |
Correct |
12 ms |
20052 KB |
Output is correct |
18 |
Correct |
12 ms |
20048 KB |
Output is correct |
19 |
Correct |
13 ms |
20052 KB |
Output is correct |
20 |
Correct |
12 ms |
20052 KB |
Output is correct |
21 |
Incorrect |
10 ms |
20032 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
20056 KB |
Output is correct |
2 |
Correct |
13 ms |
20044 KB |
Output is correct |
3 |
Correct |
13 ms |
20048 KB |
Output is correct |
4 |
Correct |
13 ms |
20048 KB |
Output is correct |
5 |
Correct |
11 ms |
20052 KB |
Output is correct |
6 |
Correct |
10 ms |
20100 KB |
Output is correct |
7 |
Correct |
11 ms |
20136 KB |
Output is correct |
8 |
Correct |
12 ms |
20084 KB |
Output is correct |
9 |
Correct |
11 ms |
20052 KB |
Output is correct |
10 |
Correct |
12 ms |
20052 KB |
Output is correct |
11 |
Correct |
11 ms |
20164 KB |
Output is correct |
12 |
Correct |
12 ms |
20044 KB |
Output is correct |
13 |
Correct |
10 ms |
20052 KB |
Output is correct |
14 |
Correct |
11 ms |
20100 KB |
Output is correct |
15 |
Correct |
10 ms |
20044 KB |
Output is correct |
16 |
Correct |
12 ms |
20100 KB |
Output is correct |
17 |
Correct |
12 ms |
20052 KB |
Output is correct |
18 |
Correct |
12 ms |
20048 KB |
Output is correct |
19 |
Correct |
13 ms |
20052 KB |
Output is correct |
20 |
Correct |
12 ms |
20052 KB |
Output is correct |
21 |
Incorrect |
10 ms |
20032 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |