QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#789887#9528. New Energy VehiclexixuTL 0ms3624kbC++232.9kb2024-11-27 22:28:172024-11-27 22:28:18

Judging History

This is the latest submission verdict.

  • [2024-11-27 22:28:18]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 3624kb
  • [2024-11-27 22:28:17]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
#define int long long
// #define int __int128
#define re read()
#define pr(x) print(x)
#define fup(a, b, c, d) for(int a = (b); a <= (c); a += (d))
#define fdo(a, b, c, d) for(int a = (b); a >= (c); a -= (d))
typedef long long ll;
typedef pair<int , int> PII;
typedef map<int , int> MII;
const int inf = 0x3f3f3f3f, N = 2e6 + 10, M = 4e5 + 10, mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;




void solve()
{
    int n, m, ssu = 0;
    cin >> n >> m;
    vector<int> a(n + 10);
    map<int , int> mp;

    fup(i, 1, n, 1) {
        cin >> a[i];
        ssu += a[i];
    }

    vector<PII> v(m + 10);
    vector<int> b(m + 10);
    fup(i, 1, m, 1) {
        int x, y;
        cin >> x >> y;
        v[i] = {x, y};
    }

    fup(i, 1, m, 1) {
        b[i] = v[i].first - v[i - 1].first;
    }

    vector<int> nxt(n + 10), la(n + 10);

    fup(i, 1, m, 1) nxt[i] = i;
    // cout << b[1] << '\n';
    fup(i, 1, m, 1) {
        int op = v[i].second;
        int nu = a[op], su = 0, f = 0;
        fup(j, la[op], i, 1) {
            if(su + b[j] <= nu) {
                b[j] = 0;
            }
            else {
                b[j] -= (nu - su);
                // cout << j << ' ' << b[j] << '\n';
                f = j;
                break ;
            }
            su += b[j];
            j = nxt[j];
        }
        if(!f) f = i;
        fup(j, la[op], f, 1) {
            nxt[j] = f;
        }
        la[op] = i + 1;
    }
    // cout << '\n';

    int an = 0;
    fup(j, 1, m, 1) {
        // cout << b[j] << ' ';
        if(an + b[j] > ssu - a[v[j].second]) {
            cout << v[j - 1].first + (ssu - an) << '\n';
            return ;
        }
        an += b[j];
    }
    // cout << "\n";
    // cout << ssu << ' ' << an << '\n';

    cout << v[m].first + (ssu - an) << '\n';
}

signed main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int _ = 1;
    cin >> _;
    while(_ --)
    {
        solve();
    }
    // fup(i, 1, _, 1) {
    //     if(i == 16 && _ == 1000) {
    //         // cout << "1238715\n";
    //         int n, m, su = 0, ssu;
    //         cin >> n >> m;
    //         // cout << n << ' ' << m << " : ";
    //         vector<int> a(n + 10);
    //         map<int , int> mp;

    //         fup(i, 1, n, 1) {
    //             cin >> a[i];
    //             // cout << a[i] << ' ';
    //             su += a[i];
    //         }
    //         // cout << " : ";
    //         ssu = su;

    //         vector<PII> v(m + 10);
    //         fup(i, 1, m, 1) {
    //             int x, y;
    //             cin >> x >> y;
    //             if(i > 12) cout << x << ' ' << y << " , ";
    //             v[i] = {x, y};
    //         }
    //         continue ;
    //     }
    //     solve();
    // }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3624kb

input:

2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1

output:

12
9

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

6
3 2
2 2 2
6 1
7 1
2 2
3 3
2 1
6 2
2 3
2 2
5 1
7 2
9 1
2 2
3 3
2 1
6 2
1 1
999999999
1000000000 1
1 1
1000000000
1000000000 1

output:

9
11
4
11
999999999
2000000000

result:

ok 6 lines

Test #3:

score: -100
Time Limit Exceeded

input:

10
230 8042
599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...

output:


result: