1 条题解

  • 0
    @ 2025-12-3 15:06:20
    • 维护整体数组的标记 tmp
    • 将加操作变为直接修改 tmp
    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
    	ios::sync_with_stdio(false);
    	cin.tie(0); cout.tie(0);
    
    	int T, m, x;
        string cmd;
    	cin >> T;
    	while (T--) {
    		cin >> m;
    		map<int, int> q;
    
            int tmp = 0;  // 数组中的数 +tmp 后才是真实的值
            while (m--) {
                cin >> cmd >> x;
                if (cmd == "P") q[x - tmp]++;
                else if (cmd == "A") tmp += x;
                else {
                    if (q.count(x - tmp)) cout << q[x - tmp] << '\n';
                    else cout << 0 << '\n';
                }
            }
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    205
    时间
    100ms
    内存
    32MiB
    难度
    4
    标签
    递交数
    45
    已通过
    22
    上传者