#include<bits/stdc++.h>
using namespace std;
const long long MAXN = 3e5+10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long n, m, que;
vector < pair < long long/**type*/, long long/**number*/ > > q[MAXN];
vector < int > pref[MAXN];
long long total[MAXN];
long long type;
long long l, r, c, k, a, b;
int t[MAXN * 4], lazy[MAXN * 4];
void push_lazy(int i, int l, int r)
{
if(lazy[i])
t[i] += (r - l + 1) * lazy[i];
if(lazy[i] && l != r)
{
lazy[2*i] += lazy[i];
lazy[2*i+1] += lazy[i];
}
lazy[i] = 0;
}
int ql, qr, val;
int query(int i, int l, int r)
{
push_lazy(i, l, r);
if(ql <= l && r <= qr)return t[i];
if(qr < l || r < ql)return 0;
int mid = (l + r)/2;
return query(2*i, l, mid) + query(2*i+1, mid+1, r);
}
void update(int i, int l, int r)
{
push_lazy(i, l, r);
if(qr < l || ql > r)return;
if(ql <= l && r <= qr)
{
lazy[i] = val;
push_lazy(i, l, r);
return;
}
int mid = (l + r)/2;
update(2*i, l, mid);
update(2*i+1, mid+1, r);
t[i] = t[2*i] + t[2*i+1];
}
void read()
{
cin >> n >> m >> que;
int last_add = 0;
for (long long i = 1; i <= que; ++ i)
{
cin >> type;
if(type == 1)
{
cin >> l >> r >> c >> k;
for (int j = l; j <= r; ++ j)
{
total[j] += k;
q[j].push_back(make_pair(c, k));
int last = 0;
if(pref[j].size())last = pref[j][pref[j].size()-1];
pref[j].push_back(last + k);
}
//cout << "ended " << endl;
}
else if(type == 2)
{
cin >> l >> r >> k;
for (int j = l; j <= r; ++ j)
{
ql = j;
qr = j;
val = min(total[j], k);
update(1, 1, n);
total[j] -= val;
}
}
else
{
cin >> a >> b;
ql = a;
qr = a;
b += query(1, 1, n);
// cout << "newb is " << b << endl;
int bl = 0, br = pref[a].size()-1, mid, bans = 0;
while(bl <= br)
{
mid = (bl + br)/2;
if(pref[a][mid] < b)
{
bl = mid + 1;
bans = mid;
}
else
{
br = mid - 1;
}
}
/*if(a == 3)
{
cout << b << endl;
for (int j = 0; j < pref[a].size(); ++ j)
cout << pref[a][j] << " ";
cout << endl;
cout << bans << endl;
}*/
if(bans + 1 >= pref[a].size())cout << 0 << endl;
else cout << q[a][bans+1].first << endl;
}
}
}
int main()
{
speed();
read();
return 0;
}
Compilation message
foodcourt.cpp: In function 'void read()':
foodcourt.cpp:119:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
119 | if(bans + 1 >= pref[a].size())cout << 0 << endl;
| ~~~~~~~~~^~~~~~~~~~~~~~~~~
foodcourt.cpp:58:9: warning: unused variable 'last_add' [-Wunused-variable]
58 | int last_add = 0;
| ^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
25056 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
25056 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1045 ms |
19028 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1032 ms |
137692 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
25056 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
963 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
25056 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
25056 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |