跳到正文

个人记录

T3 序列

Ethan_sun约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟

版本

  1. v1当前

模拟。

C++
#include <bits/stdc++.h>
#define debug(a) cerr << (#a) << " = " << (a) << endl;
#define int long long
#define endl '\n'
using namespace std;

char ch;
vector<int> x;
int t, n, a, b;
void init() {
    for (int i = 0; i <= n; i++) {
        x.push_back(i);
    }
}
void solve() {
    if (ch == 'i') {
        for (int i = a; i <= b; i++) {
            x.push_back(i);
        }
    }
    else if (ch == 'd') {
        for (int i = a; i <= b; i++) {
            x[i - 1] = -1;
        }
    }
    else if (ch == 'p') {
        int cnt = 0;
        if (a == 0) {
        	if (x[0] != -1) {
        		cnt += x[0];
			}
			a++;
		}
        for (int i = a; i <= b; i++) {
            if (x[i - 1] != -1) {
            	cnt += x[i - 1];
			}
        }
        cout << cnt << endl;
    }
//    cout << endl;
//    for (int i = 0; i < x.size(); i++) {
//    	cout << x[i] << " ";
//	}
//	cout << endl;
}
signed main() {
    cin >> t >> n;
    init();
    while (t--) {
        cin >> ch >> a >> b;
        solve();
    }
    return 0;
}
原文