题解:P11078 「FSLOI Round I」迷雾

· · 题解

首先,对于修改和移动这两个操作,很容易就可以解决,所以考虑怎样下传修改操作。即怎样快速给 c_{i+k},c_{i+2\times k},\dots,c_{i+b_i\times k} 这些操作标记修改操作。

我们发现,k \le 20 这个条件很特殊,所以从它入手。

考虑维护一个集合 multiset<int>cnt[27]。cnt_k 表示对于所有要修改的操作下标 \equiv i\bmod k \pmod k 的,最后一个要修改的操作下标 所构成的集合。有点绕,建议自行举例理解。

注意:

考场代码如下:

#include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef long long ll;
typedef pair<int, int> pr;
#define up(i, l, r) for(int i = (l); i <= (r); i++)
#define down(i, r, l) for(int i = (r); i >= (l); i--)
const int mod = 1000000007;
const int base = 2333;
const double eps = 1e-6;

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    return x * f;
}

int n, m, k, Q, T, _, ans = 0;
char a[1007][1007];
multiset<int>cnt[27];
inline void go(char ch,int &x,int &y,int u){
    if(ch=='D')x=min(n,x+u);
    if(ch=='R')y=min(m,y+u);
    if(ch=='U')x=max(1,x-u);
    if(ch=='L')y=max(1,y-u);
}
inline void turn(char &ch){
    if(ch=='U')ch='D';
    else if(ch=='D')ch='U';
    else if(ch=='L')ch='R';
    else ch='L';
}
signed main() {
    n=read(),m=read(),Q=read(),k=read();
    up(i,1,n)up(j,1,m)cin>>a[i][j];
    int x=1,y=1;
    for(int i=1;i<=Q;i++){
        char ch;cin>>ch;
        int u=read(),v=read();
        for(int j=0;j<20;j++){
            while(!cnt[j].empty()&&*cnt[j].begin()<i)cnt[j].erase(cnt[j].begin());
        }
        int t=cnt[i%k].size();
        if(t&1)turn(ch);
        go(ch,x,y,u);
        if(a[x][y]=='X')cnt[i%k].insert(i+v*k);
    }
    cout<<x<<" "<<y;
    return 0;
}