编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#30155 #2053. 帽子为什么尖尖的? Compile Error 0 0 ms 0 K C++ 17 / 843 B C192024212139 2025-03-15 23:53:38
显示原始代码
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    long long n, a_i;
    cin >> n;
    multiset<long long> hats;
    for (int i = 0; i < n; i++) {
        cin >> a_i;
        hats.insert(a_i);
    }
    int q, operate;
    cin >> q;
    int j = 0 while (j < q) {
        int l, r;
        cin >> operate;
        j++;
        switch (operate) {
            case 1: {
                int x;
                cin >> x;
                hats.insert(x);
                break;
            }
            case 2: {
                int y;
                cin >> y;
                auto it = hats.find(y);
                if (it != hats.end())
                    hats.erase(it);
                break;
            }
            case 3: {
                long long sum = 0;
                cin >> l >> r;
                for (auto i = hats.lower_bound(l); i != hats.upper_bound(r); i++) {
                    sum += *i;
                }
                cout << sum << '\n';
                break;
            }
            default:
                break;
        }
    }
    return 0;
}

编译信息

/sandbox/1/a.cpp: In function 'int main()':
/sandbox/1/a.cpp:20:2: error: expected ',' or ';' before 'while'
   20 |  while(j<q) {
      |  ^~~~~