답안 #1112350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112350 2024-11-14T06:17:31 Z onlk97 별자리 3 (JOI20_constellation3) C++14
100 / 100
234 ms 26188 KB
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
using namespace std;
using pii=pair <int,int>;
using tii=pair <pii,int>;
bool cmp(tii a,tii b){
    return a.x.y<b.x.y;
}
int bit[200010];
void upd(int pos,int val){
    for (int i=pos; i<200010; i+=i&(-i)) bit[i]+=val;
}
int qry(int pos){
    int ret=0;
    for (int i=pos; i>0; i-=i&(-i)) ret+=bit[i];
    return ret;
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    int a[n+1];
    for (int i=1; i<=n; i++) cin>>a[i];
    pii p[n+1];
    for (int i=1; i<=n; i++) p[i]={a[i],i};
    sort(p+1,p+n+1);
    int m;
    cin>>m;
    tii st[m+1];
    for (int i=1; i<=m; i++) cin>>st[i].x.x>>st[i].x.y>>st[i].y;
    sort(st+1,st+m+1,cmp);
    int ans=0,ptr=1;
    set <int> rem;
    for (int i=1; i<=n; i++) rem.insert(i);
    for (int i=1; i<=m; i++){
        while (ptr<=n&&p[ptr].x<st[i].x.y){
            rem.erase(p[ptr].y);
            ptr++;
        }
        int cost=st[i].y-qry(st[i].x.x);
        if (cost>0){
            ans+=cost;
            auto it=rem.lower_bound(st[i].x.x);
            int r=(it==rem.end()?n:(*it)-1);
            int l=(it==rem.begin()?1:*(--it)+1);
            upd(l,cost); upd(r+1,-cost);
        }
    }
    int sum=0;
    for (int i=1; i<=m; i++) sum+=st[i].y;
    cout<<sum-ans<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 2 ms 592 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 2 ms 592 KB Output is correct
28 Correct 2 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 3 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 2 ms 592 KB Output is correct
34 Correct 2 ms 664 KB Output is correct
35 Correct 3 ms 592 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 2 ms 592 KB Output is correct
38 Correct 1 ms 472 KB Output is correct
39 Correct 3 ms 592 KB Output is correct
40 Correct 2 ms 592 KB Output is correct
41 Correct 2 ms 592 KB Output is correct
42 Correct 2 ms 592 KB Output is correct
43 Correct 2 ms 760 KB Output is correct
44 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 2 ms 592 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 2 ms 592 KB Output is correct
28 Correct 2 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 3 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 2 ms 592 KB Output is correct
34 Correct 2 ms 664 KB Output is correct
35 Correct 3 ms 592 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 2 ms 592 KB Output is correct
38 Correct 1 ms 472 KB Output is correct
39 Correct 3 ms 592 KB Output is correct
40 Correct 2 ms 592 KB Output is correct
41 Correct 2 ms 592 KB Output is correct
42 Correct 2 ms 592 KB Output is correct
43 Correct 2 ms 760 KB Output is correct
44 Correct 2 ms 592 KB Output is correct
45 Correct 234 ms 25928 KB Output is correct
46 Correct 225 ms 25716 KB Output is correct
47 Correct 221 ms 25928 KB Output is correct
48 Correct 229 ms 25736 KB Output is correct
49 Correct 221 ms 25672 KB Output is correct
50 Correct 212 ms 25416 KB Output is correct
51 Correct 207 ms 25596 KB Output is correct
52 Correct 223 ms 26188 KB Output is correct
53 Correct 233 ms 25848 KB Output is correct
54 Correct 150 ms 26184 KB Output is correct
55 Correct 151 ms 25852 KB Output is correct
56 Correct 156 ms 25416 KB Output is correct
57 Correct 144 ms 25404 KB Output is correct
58 Correct 146 ms 25160 KB Output is correct
59 Correct 140 ms 25416 KB Output is correct
60 Correct 130 ms 24392 KB Output is correct
61 Correct 155 ms 25740 KB Output is correct
62 Correct 148 ms 25428 KB Output is correct
63 Correct 213 ms 25428 KB Output is correct
64 Correct 163 ms 24780 KB Output is correct
65 Correct 147 ms 25424 KB Output is correct
66 Correct 148 ms 25476 KB Output is correct