#include<iostream>
#include<vector>
using namespace std;
int n, q, opt, i ,j, k;
int main() {
cin >> n >> q;
vector< vector<int> > locker(n + 1);
while(q--) {
cin >> opt;
if(opt == 1) {
cin >> i >> j >> k;
if(locker[i].size() < j) locker[i].resize(j + 1);
locker[i][j] = k;
}
else {
cin >> i >> j;
cout << locker[i][j] << endl;
}
}
return 0;
}
#include<iostream>
#include<stack>
using namespace std;
stack<int> n;
int s = 0, x, y;
int main() {
char ch;
do {
ch = getchar();
if(ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
else if (ch == '.') n.push(s), s = 0;
else if (ch != '@') {
x = n.top(); n.pop(); y = n.top(); n.pop();
switch(ch) {
case '+': n.push(y + x); break;
case '-': n.push(y - x); break;
case '*': n.push(y * x); break;
case '/': n.push(y / x); break;
}
}
} while(ch != '@');
cout << n.top() << endl;
return 0;
}
//队列实现
#include<iostream>
#include<queue>
using namespace std;
queue <int> q;
int n, m;
int main() {
cin >> n >> m;
for(int i = 1; i <= n; i++) q.push(i);
while(q.size()) {
for(int i = 1; i < m; i++) {
q.push(q.front());
q.pop();
}
cout << q.front() << ' ';
q.pop();
}
return 0;
}
//链表实现
#include<iostream>
#include<list>
using namespace std;
list <int> a;
int main() {
int n, m, cnt = 0;
cin >> n >> m;
for(int i = 1; i <= n; i++)
a.push_back(i);
list <int> :: iterator it, now;
it = a.begin();
while(!a.empty()) {
cnt++;
now = it;
if(++it == a.end()) it = a.begin();
if(cnt == m) {
cout << *now << ' ';
a.erase(now);
cnt = 0;
}
}
return 0;
}
//可变数组vector方法
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector <int> v;
int main() {
int m, n, t, ans = 0;
cin >> m >> n;
while (cin >> t) {
if (find(v.begin(), v.end(), t) == v.end()) {
v.push_back(t);
ans++;
}
if (v.size() > m)
v.erase(v.begin());
}
cout << ans << endl;
}
#include<iostream>
#include<queue>
using namespace std;
const int MAXN = 1e5 + 5;
struct node {
int t, x;
} tx;
queue <node> ship;
int n, t, k, x, ans;
int temp[MAXN];
int main() {
cin >> n;
while(n--) {
cin >> t >> k;
while(!ship.empty()) {
tx = ship.front();
if(tx.t + 86400 <= t) {
ship.pop();
temp[tx.x]--;
if(!temp[tx.x]) ans--;
continue;
}
break;
}
while(k--) {
cin >> x;
tx.t = t, tx.x = x;
ship.push(tx);
temp[tx.x]++;
if(temp[tx.x] == 1) ans++;
}
cout << ans << endl;
}
return 0;
}
#include<iostream>
#include<stack>
using namespace std;
stack <int> q;
int p, n;
int main() {
cin >> p;
while(p--) {
cin >> n;
int a[n+1], b[n+1], sum = 1;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> b[i];
for(int i = 1; i <= n; i++) {
q.push(a[i]);
while(q.top() == b[sum]) {
q.pop(), sum++;
if(q.empty()) break;
}
}
if(q.empty()) cout << "Yes" << endl;
else cout << "No" << endl;
while(!q.empty()) q.pop();
}
return 0;
}
#include<iostream>
#include<list>
#include<algorithm>
#include<cmath>
using namespace std;
const int MAXN = 32767;
int b[MAXN];
list <int> s;
list <int> :: iterator now, it, index[MAXN];
struct volume {
int ai, l;
} a[MAXN];
bool cmp(volume x, volume y) {
return x.ai < y.ai;
}
int main() {
int n, sum = 0;
cin >> n;
for(int i = 0; i < n; i++) {
cin >> a[i].ai;
a[i].l = i;
}
sort(a, a + n, cmp);
it = s.begin();
for(int i = 0; i < n; i++) {
s.push_back(a[i].ai);
index[i] = ++it;
b[a[i].l] = i;
}
while(n--) {
int min = 1e6;
now = index[b[n]];
if(s.size() == 1) min = *now;
else {
it = now;
if(it-- != s.begin()) if(fabs(*it - *now) < min) min = fabs(*it - *now);
it = now;
if(++it != s.end()) if(fabs(*it - *now) < min) min = fabs(*it - *now);
}
s.erase(now);
sum += min;
}
cout << sum << endl;
return 0;
}