QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#510242#6531. Base Station Constructionucup-team3474WA 58ms13228kbC++231.2kb2024-08-09 00:25:262024-08-09 00:25:27

Judging History

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

  • [2024-08-09 00:25:27]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:13228kb
  • [2024-08-09 00:25:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1919810;
typedef long long ll;
typedef pair<ll,ll> PII;
ll n,m,k;
ll a[N],b[N];
ll dp[N];
ll ne[N];
ll q[N],tt,hh;

int s[N];

void __(){
    scanf("%lld",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++) dp[i]=0;
    vector<PII> v;
    scanf("%lld",&m);
    bool flag=1;
    int mx=0;
    for(int i=1;i<=m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        mx=max(mx,x);
        if(y==n)  flag=0;
        v.push_back({y,x});
    }
    sort(v.begin(),v.end());
    int j=0;
    for(int i=1;i<=n;i++){
        ne[i]=ne[i-1];
        while(j<v.size()&&v[j].first<i){
            ne[i]=max(ne[i],v[j].second);
            j++;
        } 
        // cout<<ne[i]<<" ";
    }
    // cout<<endl;
    tt=0,hh=0;
    q[0]=0;
    
    for(int i=1;i<=n;i++){
        while(hh<=tt&&q[hh]<ne[i]) hh++;
        dp[i]=dp[q[hh]]+a[i];
        while(hh<=tt&&dp[i]<dp[q[hh]]) tt--;
        q[++tt]=i;
    }
    ll mn=1e18;
    for(int i=mx;i<=n;i++) mn=min(mn,dp[i]);
    printf("%lld\n",mn);
}


int main(){
    int _=1;
    cin>>_;
    while(_--){
        __();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9920kb

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: 58ms
memory: 13228kb

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:

209
48
4
157
362
141
23
220
174
139
176
206
136
104
230
127
287
89
156
130
148
46
1
193
265
93
239
303
236
150
177
57
46
18
91
66
83
160
151
62
35
168
156
81
171
158
54
242
126
121
296
86
311
244
333
87
302
81
239
173
30
129
75
113
90
179
81
382
142
163
77
176
194
373
211
53
90
17
234
101
340
137
18...

result:

wrong answer 1st numbers differ - expected: '141', found: '209'