QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#718575#7903. Computational Intelligenceretired_midlightsTL 0ms0kbC++141.6kb2024-11-06 20:53:302024-11-06 20:53:31

Judging History

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

  • [2024-11-06 20:53:31]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-06 20:53:30]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i <= (int)b; i ++)
#define per(i, a, b) for(int i = (int)a; i >= (int)b; i --)
#define ll long long
using namespace std;
const int maxn = 100010;
int n, m, a[maxn], b[maxn], t[maxn], nxt[maxn];
ll x[maxn];
void solve() {
    cin >> n >> m;
    rep(i, 1, n) cin >> a[i], b[i] = a[i];
    priority_queue < pair < int, int > > pq;
    map < int, int > mp;
    rep(i, 1, m) {
        cin >> x[i] >> t[i];
        pq.push(make_pair(-i, t[i]));
    }
    per(i, m, 1) {
        if(mp.find(x[i]) != mp.end()) nxt[i] = mp[x[i]], mp[x[i]] = i;
        else mp[x[i]] = i, nxt[i] = m + 1;
    }
    rep(i, 1, n) pq.push(make_pair(-(m + 1), i));
    ll cur = 0, num = 1;
    x[m + 1] = 1e18;
    while(!pq.empty()) {
        if(pq.top().first > -num) pq.pop();
        auto u = pq.top();
        while(cur + b[u.second] < x[num]) {
            cur += b[u.second];
            b[u.second] = 0;
            pq.pop();
            if(pq.empty()) {
                cout << cur << '\n';
                return;
            }
            u = pq.top();
        }
        b[u.second] -= x[num] - cur;
        cur = x[num];
        b[t[num]] = a[t[num]];
        // rep(i, 1, n) cerr << b[i] << " \n"[i == n];
        if(nxt[num] < -u.first) {
            // cerr << "add" << '\n';
            pq.push(make_pair(-nxt[num], t[num]));
        }
        num ++;
    }
}

int main() {
#ifdef LOCAL
    freopen("data.in", "r", stdin);
#endif
    ios :: sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int T = 1;
    cin >> T;
    while(T --) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3
0 0 1 0
0 0 1 0
0 0 1 0
0 0 0 1
0 0 1 0
0 1 1 1

output:


result: