This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
deque < pair < long long/**type*/, long long/**number*/ > > q[MAXN];
long long total[MAXN];
long long t;
long long l, r, c, k, a, b;
void read()
{
cin >> n >> m >> que;
for (long long i = 1; i <= que; ++ i)
{
cin >> t;
if(t == 1)
{
cin >> l >> r >> c >> k;
for (long long j = l; j <= r; ++ j)
{
q[j].push_back(make_pair(c, k));
total[j] += k;
}
}
else if(t == 2)
{
cin >> l >> r >> k;
for (long long j = l; j <= r; ++ j)
{
if(total[j] <= k)
{
q[j].clear();
total[j] = 0;
}
else
{
int kk = k;
total[j] -= kk;
while(kk)
{
if(kk >= q[j].front().second)
{
kk -= q[j].front().second;
// cout << "cut " << q[j].front().first << endl;
q[j].pop_front();
}
else
{
q[j].front().second -= kk;
kk = 0;
}
}
}
}
}
else
{
cin >> a >> b;
// cout << "start " << endl;
if(total[a] < b)cout << 0 << endl;
else
{
deque < pair <long long, long long > >cut;
long long sum = b, last_colour = 0;
while(sum > 0)
{
sum -= q[a].front().second;
last_colour = q[a].front().first;
// cout << "** " << last_colour << endl;
cut.push_back(q[a].front());
q[a].pop_front();
}
while(!cut.empty())
{
q[a].push_front(cut.back());
cut.pop_back();
}
cout << last_colour << endl;
}
}
}
}
int main()
{
speed();
read();
return 0;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |