比赛 国庆欢乐赛3 评测结果 AAAAAAAAAAAAAAA
题目名称 Following Directions 最终得分 100
用户昵称 xuyuqing 运行时间 1.959 s
代码语言 C++ 内存使用 22.88 MiB
提交时间 2025-10-05 09:10:21
显示代码纯文本

#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

const int N = 1515;

int n;
long long nums[N][N];
long long sums[N][N];
long long res;
int q;

int main () {
    
    freopen ("zunxun.in", "r", stdin);
    freopen ("zunxun.out", "w", stdout);
    
    cin >> n;
    char ch;
    for (int i = 1; i <= n + 1; i++) {
        for (int j = 1; j <= n + 1; j++) {
            sums[i][j] += 1;
            if (i <= n && j <= n) {
                cin >> ch;
                nums[i][j] = ch;
                if (ch == 'R') {
                    sums[i][j + 1] += sums[i][j];
                }
                else {
                    sums[i + 1][j] += sums[i][j];
                }
            }
            else if (i != n + 1 || j != n + 1) {
                cin >> nums[i][j];
                res += nums[i][j] * (sums[i][j] - 1);
            }
        }
    }
    
    cout << res << endl;
    
    cin >> q;
    int x;
    int y;
    for (int i = 1; i <= q; i++) {
        cin >> x >> y;
        int xx = x;
        int yy = y;
        long long num1;
        long long num2;
        if (nums[x][y] == 'R') {
            yy++;
            nums[x][y] = 'D';
        }
        else {
            xx++;
            nums[x][y] = 'R';
        }
        
        while (true) {
            num1 = nums[xx][yy];
            sums[xx][yy] -= sums[x][y];
            if (xx == n + 1 || yy == n + 1) {
                break;
            }
            if (nums[xx][yy] == 'R') {
                yy++;
            }
            else {
                xx++;
            }
        }
        
        if (nums[x][y] == 'R') {
            xx = x;
            yy = y + 1;
        }
        else {
            xx = x + 1;
            yy = y;
        }
        
        while (true) {
            num2 = nums[xx][yy];
            sums[xx][yy] += sums[x][y];
            if (xx == n + 1 || yy == n + 1) {
                break;
            }
            if (nums[xx][yy] == 'R') {
                yy++;
            }
            else {
                xx++;
            }
        }
        
        res += (num2 - num1) * (sums[x][y]);
        cout << res << endl;
    }
    
    return 0; 
}