QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#769353#9730. Elevator IImapleKingCompile Error//C++201.6kb2024-11-21 17:15:572024-11-21 17:15:58

Judging History

你现在查看的是最新测评结果

  • [2024-11-21 17:15:58]
  • 评测
  • [2024-11-21 17:15:57]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize(2)

// using namespace std;

using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;

struct node
{
    int x, y;
    friend bool operator < (node a, node b){
        return a.y < b.y; 
    }
};

void solve() {
    int n, f;
    std::cin >> n >> f;
    std::vector<std::pair<int, int>> a(n);
    for(auto &[x, y] : a){
        std::cin >> x >> y;
    }
    i64 ans = 0;
    std::sort(a.begin(), a.end());
    std::priority_queue<node> q;
    int p = 0;
    while(p < n && a[p].first <= f){
        q.push({a[p].first, a[p].second});
        p++;
    }
    while(p < n){
        if (q.size() && q.top().y >= f){
            node cur = q.top();
            q.pop();
            ans += cur.y - cur.x;
            f = cur.y;
            while(p < n && a[p].first <= f){
                q.push({a[p].first, a[p].second});
                p++;
            }
        }else{
            ans += a[p].second - cur;
            cur = a[p].second;
            p++;
            while(p < n && a[p].first <= f){
                q.push({a[p].first, a[p].second});
                p++;
            }
        }
    }
    while(q.size()){
        node cur = q.top();
        q.pop();
        ans += cur.y - cur.x;
    }
    std::cout << ans << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    // std::cout << std::fixed << std::setprecision(10); // 固定输出精度
    int t = 1;
    std::cin >> t;

    while (t--) {
        solve();
    }
    

    return 0;
}

详细

answer.code: In function ‘void solve()’:
answer.code:44:34: error: ‘cur’ was not declared in this scope
   44 |             ans += a[p].second - cur;
      |                                  ^~~