QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#697336#6531. Base Station Constructionenze114514WA 144ms7672kbC++202.0kb2024-11-01 13:18:272024-11-01 13:18:27

Judging History

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

  • [2024-11-01 13:18:27]
  • 评测
  • 测评结果:WA
  • 用时:144ms
  • 内存:7672kb
  • [2024-11-01 13:18:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

#define pb push_back

template<typename T>
T chmax(T a, T b) {
    return a > b ? a : b;
}
 
template<typename T>
T chmin(T a, T b) {
    return a > b ? b : a;
}

const ld pi = 3.14159265358979323846;
const int mod = 998244353;
const ll INF = 1e18;

const int N = (int)1e5 + 1, M = N * 2;

bool cmp(vector<int> a, vector<int> b){
    return a[1] == b[1] ? a[0] < b[0] : a[1] < b[1];
}

int cnt = 0;

void solve(){
    int n;
    cin >> n;

    int a[n + 1], r[n + 1];
    ll f[n + 1];
cnt++;
    string s = "";

    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(cnt == 25){
            s += " " + to_string(a[i]) + " ";
        }
        f[i] = INF;
        r[i] = 0;
    }

    int m;
    cin >> m;

    
    vector<vector<int>> b(m, vector<int>(2));
    for(int i = 0; i < m; i++){
        cin >> b[i][0] >> b[i][1];
        if(cnt == 25){
            s += " (" + to_string(b[i][0]) + ", " + to_string(b[i][1]) + ") "; 
        }
    }

if(cnt == 25) cout << s << endl;
    sort(b.begin(), b.end(), cmp);
    for(int i = 0, j = 0, k = 0; i <= n; i++){
        while(j < m && b[j][1] < i){
            k = chmax(k, b[j][0]);
            j++;
        }
        r[i] = k;
    }

    f[0] = 0;
    deque<int> q;
    q.push_back(0);

    for(int i = 1; i <= n; i++){
        while(!q.empty() && q.front() < r[i]){
            q.pop_front();
        }
        if(!q.empty()){
            f[i] = chmin(f[i], f[q.front()] + a[i]);
        }
        while(!q.empty() && f[q.back()] >= f[i]){
            q.pop_back();
        }
        q.push_back(i);
    }

    ll qwq = INF;
    for(int i = b[m - 1][0]; i <= b[m - 1][1]; i++){
        qwq = chmin(qwq, f[i]);
    }
    cout << qwq << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;

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

詳細信息

Test #1:

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

input:

2
5
3 2 4 1 100
3
1 3
2 4
5 5
5
7 3 4 2 2
3
1 4
2 3
4 5

output:

102
5

result:

ok 2 number(s): "102 5"

Test #2:

score: -100
Wrong Answer
time: 144ms
memory: 7672kb

input:

6201
12
88 78 46 95 84 98 55 3 68 42 6 18
19
6 9
10 11
12 12
8 11
8 12
2 3
2 3
1 5
9 9
7 8
6 11
2 4
12 12
2 4
2 9
7 10
8 8
1 7
6 11
5
76 27 48 66 61
2
1 4
3 5
8
64 81 20 6 86 9 4 55
1
7 7
9
1 43 18 81 11 22 9 61 83
14
5 6
2 6
5 8
1 4
9 9
9 9
7 7
2 5
8 9
5 6
4 8
5 8
9 9
6 6
10
66 41 84 7 80 31 22 96 ...

output:

141
48
4
126
303
141
23
170
159
139
153
194
136
89
230
93
287
89
124
130
148
27
1
193
 36  57  36  67  94  84  16  59  83  55  82  97  26  28  33  34  (12, 13)  (6, 9)  (6, 14)  (11, 14)  (3, 11)  (1, 15)  (3, 15)  (3, 16)  (13, 15)  (1, 16)  (10, 10)  (14, 14)  (7, 7)  (3, 11)  (7, 11)  (10, 13)  (...

result:

wrong answer 25th numbers differ - expected: '194', found: '36'