QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217276 | #5114. Cells Coloring | ucup-team1001 | TL | 0ms | 0kb | C++20 | 2.2kb | 2023-10-16 18:01:34 | 2023-10-16 18:01:34 |
answer
#include<bits/stdc++.h>
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
#define irep(i,l,r) for(int i = l; i <= r; ++ i)
const int N = 100099;
const int len = 370;
const int K = N / len + 50;
int per[N][555],invp[N][555];
struct stak{
int tot;
int opt[505][2];
stak(){tot = 0;}
void push(int x,int y){
opt[++ tot][0] = x, opt[tot][1] = y;
}
void top(int &x, int &y){
x = opt[tot][0], y = opt[tot][1];
}
void pop(){
-- tot;
}
int size(){
return tot;
}
};
stak p[555];
inline int read(){
char ch = getchar();
int s = 0;
while(!isdigit(ch))ch = getchar();
while(isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
return s;
}
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n = read(), m = read(), q = read();
vector<array<int,2>>quests(q);
vector<array<int,2>>bd;
irep(i, 0, q - 1){
if(read() == 1){
int line = read(), cloumn = read();
quests[i] = {cloumn, line};
bd.push_back({cloumn, line});
}
else
{
int pos = read();
quests[i] = {pos, -1};
}
}
sort(bd.begin(), bd.end());
for(int c = 0; c <= bd.size() / len; c ++)
for(int i = 1; i <= n; ++ i)
per[i][c] = invp[i][c] = i;
irep(ii, 0, q - 1){
if(quests[ii][1] != -1){
auto [cloumn, line] = quests[ii];
array<int, 2>arr = {cloumn, line};
int x = upper_bound(bd.begin(), bd.end(), arr) - bd.begin();
x /= len;
stak temp;
while(p[x].size()){
int c, l;
p[x].top(c, l);
if(c < cloumn)break;
int tx, ty;
p[x].top(tx, ty);
temp.push(tx, ty);
per[invp[l][x]][x] = l + 1;
per[invp[l + 1][x]][x] = l;
swap(invp[l][x], invp[l + 1][x]);
p[x].pop();
}
temp.push(cloumn, line);
while(temp.size()){
int c, l;
temp.top(c, l);
per[invp[l][x]][x] = l + 1;
per[invp[l + 1][x]][x] = l;
swap(invp[l][x], invp[l + 1][x]);
int tx, ty;
temp.top(tx, ty);
p[x].push(tx, ty);
temp.pop();
}
}
else{
int a = quests[ii][0];
for(int x = 0; x <= bd.size() / len; ++ x){
a = per[a][x];
}
cout << a << '\n';
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
3 4 2 1 .*** *..* **..