using namespace std;
using namespace __gnu_pbds;
#define int long long
typedef int64_t ll;
typedef long double ld;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define RF(n) RFi(i,n)
#define RFi(i,n) RFl(i,0,n)
#define RFl(i,l,n) for(int i=n-1;i>=l;i--)
#define all(v) begin(v),end(v)
#define siz(v) (ll(v.size()))
#define get_pos(v,x) (lower_bound(all(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define mem(v,x) memset(v,x,sizeof v)
#define ff first
#define ss second
#define mid ((l+r)>>1)
#define RAN(a,b) uniform_int_distribution<int> (a, b)(rng)
#define debug(x) (cerr << (#x) << " = " << x << "\n")
template <typename T> using max_heap = __gnu_pbds::priority_queue<T,less<T> >;
template <typename T> using min_heap = __gnu_pbds::priority_queue<T,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int maxN = 250010;
vector<int> qs[maxN];
int N,M,Q;
namespace sub3{
const int maxN = 65010;
void solve(){
deque<int> shop[maxN];
Fi(j, Q){
vector<int> curr = qs[j];
if(curr[0] == 1){
Fl(i, curr[1], curr[2]+1){
shop[i].push_back(curr[3]);
}
}
if(curr[0] == 2){
Fl(i, curr[1], curr[2]+1){
int K = curr[3];
if((int)shop[i].size() <= K) shop[i].clear();
else{
Fi(j, K) shop[i].pop_front();
}
}
}
if(curr[0] == 3){
if( (int)shop[curr[1]].size() >= curr[2]){
cout << shop[curr[1]][curr[2]-1];
}else{
cout << 0;
}
cout << "\n";
}
}
}
}
namespace sub2{
const int maxN = 2e3+10;
void solve(){
deque<pii> shop[maxN];
Fi(j, Q){
vector<int> curr = qs[j];
if(curr[0] == 1){
Fl(i, curr[1], curr[2]+1){
shop[i].push_back(mp(curr[3], curr[4]));
}
}
if(curr[0] == 2){
Fl(i, curr[1], curr[2]+1){
int K = curr[3];
while(!shop[i].empty() && K){
if(shop[i][0].ss > K){
shop[i][0].ss -= K;
K = 0;
}else{
K -= shop[i][0].ss;
shop[i].pop_front();
}
}
}
}
if(curr[0] == 3){
int b = curr[2];
deque<pii> now = shop[curr[1]];
for(pii p : now){
if(b <= p.ss){
cout << p.ff << "\n";
b = 0;
break;
}else{
b -= p.ss;
}
}
if(b) cout << "0\n";
}
}
}
}
signed main(){
cin >> N >> M >> Q;
int x;
F(Q){
int t;
cin >> t;
qs[i].pb(t);
Fi(j, 5-t){
cin >> x;
qs[i].pb(x);
}
}
if(N <= 2000 && Q <= 2000){
sub2::solve();
return 0;
}
bool __sub3 = true;
F(Q){
if(qs[i][0] == 1 && (qs[i][2] - qs[i][1] > 10 || qs[i][4] != 1)){
__sub3 = false;
}
}
if( N <= 65000 && Q <= 65000 && __sub3){
sub3::solve();
return 0;
}
return 0;
}
Compilation message
foodcourt.cpp:2:17: error: '__gnu_pbds' is not a namespace-name
2 | using namespace __gnu_pbds;
| ^~~~~~~~~~
foodcourt.cpp:4:9: error: 'int64_t' does not name a type
4 | typedef int64_t ll;
| ^~~~~~~
foodcourt.cpp:6:1: error: 'mt19937' does not name a type
6 | mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
| ^~~~~~~
foodcourt.cpp:27:40: error: '__gnu_pbds' does not name a type
27 | template <typename T> using max_heap = __gnu_pbds::priority_queue<T,less<T> >;
| ^~~~~~~~~~
foodcourt.cpp:28:40: error: '__gnu_pbds' does not name a type
28 | template <typename T> using min_heap = __gnu_pbds::priority_queue<T,greater<T> >;
| ^~~~~~~~~~
foodcourt.cpp:29:35: error: 'tree' does not name a type
29 | template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
| ^~~~
foodcourt.cpp:32:1: error: 'vector' does not name a type
32 | vector<int> qs[maxN];
| ^~~~~~
foodcourt.cpp: In function 'void sub3::solve()':
foodcourt.cpp:39:5: error: 'deque' was not declared in this scope
39 | deque<int> shop[maxN];
| ^~~~~
foodcourt.cpp:1:1: note: 'std::deque' is defined in header '<deque>'; did you forget to '#include <deque>'?
+++ |+#include <deque>
1 | using namespace std;
foodcourt.cpp:3:13: error: expected primary-expression before 'long'
3 | #define int long long
| ^~~~
foodcourt.cpp:39:11: note: in expansion of macro 'int'
39 | deque<int> shop[maxN];
| ^~~
foodcourt.cpp:41:7: error: 'vector' was not declared in this scope
41 | vector<int> curr = qs[j];
| ^~~~~~
foodcourt.cpp:1:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
+++ |+#include <vector>
1 | using namespace std;
foodcourt.cpp:3:13: error: expected primary-expression before 'long'
3 | #define int long long
| ^~~~
foodcourt.cpp:41:14: note: in expansion of macro 'int'
41 | vector<int> curr = qs[j];
| ^~~
foodcourt.cpp:42:10: error: 'curr' was not declared in this scope
42 | if(curr[0] == 1){
| ^~~~
foodcourt.cpp:44:11: error: 'shop' was not declared in this scope
44 | shop[i].push_back(curr[3]);
| ^~~~
foodcourt.cpp:47:10: error: 'curr' was not declared in this scope
47 | if(curr[0] == 2){
| ^~~~
foodcourt.cpp:50:19: error: 'shop' was not declared in this scope
50 | if((int)shop[i].size() <= K) shop[i].clear();
| ^~~~
foodcourt.cpp:56:10: error: 'curr' was not declared in this scope
56 | if(curr[0] == 3){
| ^~~~
foodcourt.cpp:57:18: error: 'shop' was not declared in this scope
57 | if( (int)shop[curr[1]].size() >= curr[2]){
| ^~~~
foodcourt.cpp:58:11: error: 'cout' was not declared in this scope
58 | cout << shop[curr[1]][curr[2]-1];
| ^~~~
foodcourt.cpp:1:1: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
+++ |+#include <iostream>
1 | using namespace std;
foodcourt.cpp:60:11: error: 'cout' was not declared in this scope
60 | cout << 0;
| ^~~~
foodcourt.cpp:60:11: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
foodcourt.cpp:62:9: error: 'cout' was not declared in this scope
62 | cout << "\n";
| ^~~~
foodcourt.cpp:62:9: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
foodcourt.cpp: In function 'void sub2::solve()':
foodcourt.cpp:72:5: error: 'deque' was not declared in this scope
72 | deque<pii> shop[maxN];
| ^~~~~
foodcourt.cpp:72:5: note: 'std::deque' is defined in header '<deque>'; did you forget to '#include <deque>'?
foodcourt.cpp:10:13: error: 'pair' was not declared in this scope
10 | #define pii pair<int,int>
| ^~~~
foodcourt.cpp:72:11: note: in expansion of macro 'pii'
72 | deque<pii> shop[maxN];
| ^~~
foodcourt.cpp:1:1: note: 'std::pair' is defined in header '<utility>'; did you forget to '#include <utility>'?
+++ |+#include <utility>
1 | using namespace std;
foodcourt.cpp:3:13: error: expected primary-expression before 'long'
3 | #define int long long
| ^~~~
foodcourt.cpp:10:18: note: in expansion of macro 'int'
10 | #define pii pair<int,int>
| ^~~
foodcourt.cpp:72:11: note: in expansion of macro 'pii'
72 | deque<pii> shop[maxN];
| ^~~
foodcourt.cpp:74:7: error: 'vector' was not declared in this scope
74 | vector<int> curr = qs[j];
| ^~~~~~
foodcourt.cpp:74:7: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
foodcourt.cpp:3:13: error: expected primary-expression before 'long'
3 | #define int long long
| ^~~~
foodcourt.cpp:74:14: note: in expansion of macro 'int'
74 | vector<int> curr = qs[j];
| ^~~
foodcourt.cpp:75:10: error: 'curr' was not declared in this scope
75 | if(curr[0] == 1){
| ^~~~
foodcourt.cpp:77:11: error: 'shop' was not declared in this scope
77 | shop[i].push_back(mp(curr[3], curr[4]));
| ^~~~
foodcourt.cpp:8:12: error: 'make_pair' was not declared in this scope
8 | #define mp make_pair
| ^~~~~~~~~
foodcourt.cpp:77:29: note: in expansion of macro 'mp'
77 | shop[i].push_back(mp(curr[3], curr[4]));
| ^~
foodcourt.cpp:8:12: note: 'std::make_pair' is defined in header '<utility>'; did you forget to '#include <utility>'?
8 | #define mp make_pair
| ^~~~~~~~~
foodcourt.cpp:77:29: note: in expansion of macro 'mp'
77 | shop[i].push_back(mp(curr[3], curr[4]));
| ^~
foodcourt.cpp:80:10: error: 'curr' was not declared in this scope
80 | if(curr[0] == 2){
| ^~~~
foodcourt.cpp:83:18: error: 'shop' was not declared in this scope
83 | while(!shop[i].empty() && K){
| ^~~~
foodcourt.cpp:94:10: error: 'curr' was not declared in this scope
94 | if(curr[0] == 3){
| ^~~~
foodcourt.cpp:3:13: error: expected primary-expression before 'long'
3 | #define int long long
| ^~~~
foodcourt.cpp:10:18: note: in expansion of macro 'int'
10 | #define pii pair<int,int>
| ^~~
foodcourt.cpp:96:15: note: in expansion of macro 'pii'
96 | deque<pii> now = shop[curr[1]];
| ^~~
foodcourt.cpp:3:13: error: expected primary-expression before 'long'
3 | #define int long long
| ^~~~
foodcourt.cpp:10:18: note: in expansion of macro 'int'
10 | #define pii pair<int,int>
| ^~~
foodcourt.cpp:97:13: note: in expansion of macro 'pii'
97 | for(pii p : now){
| ^~~
foodcourt.cpp:106:9: error: expected primary-expression before 'if'
106 | if(b) cout << "0\n";
| ^~
foodcourt.cpp:105:10: error: expected ';' before 'if'
105 | }
| ^
| ;
106 | if(b) cout << "0\n";
| ~~
foodcourt.cpp:106:9: error: expected primary-expression before 'if'
106 | if(b) cout << "0\n";
| ^~
foodcourt.cpp:105:10: error: expected ')' before 'if'
105 | }
| ^
| )
106 | if(b) cout << "0\n";
| ~~
foodcourt.cpp:97:12: note: to match this '('
97 | for(pii p : now){
| ^
foodcourt.cpp:106:15: error: 'cout' was not declared in this scope
106 | if(b) cout << "0\n";
| ^~~~
foodcourt.cpp:106:15: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:114:3: error: 'cin' was not declared in this scope
114 | cin >> N >> M >> Q;
| ^~~
foodcourt.cpp:114:3: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
foodcourt.cpp:119:5: error: 'qs' was not declared in this scope; did you mean 'ss'?
119 | qs[i].pb(t);
| ^~
| ss
foodcourt.cpp:133:8: error: 'qs' was not declared in this scope; did you mean 'ss'?
133 | if(qs[i][0] == 1 && (qs[i][2] - qs[i][1] > 10 || qs[i][4] != 1)){
| ^~
| ss