답안 #557948

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
557948 2022-05-06T10:37:21 Z new_acc Akcija (COCI21_akcija) C++14
110 / 110
1320 ms 46624 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=2e3+10;
const int SS=1<<12;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=913;
const int L=20;
int seg[(SS<<1)+10],lazy[(SS<<1)+10],pop[N*N],akt[N][N],kt[N*N],pierw[N],n,wsk,wsk2,ff[N];
pair<int,int>t[N];
bitset<N>bi[N];
set<pair<pair<int,ll>,int> >s;
vi base;
void push(int v){
    lazy[v<<1]+=lazy[v],lazy[(v<<1)+1]+=lazy[v];
    seg[v<<1]+=lazy[v],seg[(v<<1)+1]+=lazy[v];
    lazy[v]=0;
}
void upd(int a,int b,int x,int p=0,int k=SS-1,int v=1){
    if(p>b or k<a) return;
    if(p>=a and k<=b){
        lazy[v]+=x,seg[v]+=x;
        return;
    }
    push(v);
    upd(a,b,x,p,(p+k)>>1,v<<1),upd(a,b,x,((p+k)>>1)+1,k,(v<<1)+1);
    seg[v]=min(seg[v<<1],seg[(v<<1)+1]);
}
int Query(int a,int b,int p=0,int k=SS-1,int v=1){
    if(p>b or k<a) return INFi;
    if(p>=a and k<=b){
        base.push_back(v);
        return seg[v];
    }
    push(v);
    int wtf=Query(a,b,p,(p+k)>>1,v<<1);
    return min(wtf,Query(a,b,((p+k)>>1)+1,k,(v<<1)+1));
}
int Query2(int v){
    if(v>SS) return v-SS;
    push(v);
    if(seg[(v<<1)]<=0) return Query2(v<<1);
    else return Query2((v<<1)+1);
}
void clear(int v){
    lazy[v]=0;
    if(v>SS){
        seg[v]=v-SS;
        return;
    }
    clear(v<<1),clear((v<<1)+1);
    seg[v]=min(seg[(v<<1)],seg[(v<<1)+1]);
}
void cnt(int sid,int id){
    clear(1);
    for(int i=1;i<=n;i++){
        if(bi[pop[id]][i] and i<kt[id]) akt[sid][i]=1;
        else{
            if(bi[pop[id]][i] and i==kt[id]) akt[sid][i]=-1;
            else akt[sid][i]=akt[pop[id]][i];
        }
    }
    for(int i=1;i<=n;i++)
        if(akt[sid][i]==1) upd(t[i].se,n,-1);
    for(int i=1;i<=n;i++){
        if(akt[sid][i]!=0) continue;
        base.clear();
        if(akt[sid][i]==0 and Query(t[i].se,n)>0) upd(t[i].se,n,-1),bi[sid][i]=1;
        else{
            ff[i]=-1;
            for(auto u:base){
                if(seg[u]<=0){
                    ff[i]=Query2(u);
                    break;
                }
            }
        }
    }
    vector<pair<int,int> >deq;
    auto bs=[&](int pocz,int kon,int x){
        int sr,res=-1;
        while(pocz<=kon){
            sr=(pocz+kon)>>1;
            if(deq[sr].fi>=x) pocz=sr+1,res=deq[sr].se;
            else kon=sr-1;
        }
        return res;
    };
    for(int i=n;i>=1;i--){
        if(akt[sid][i]==1 or akt[sid][i]==-1) continue;
        if(bi[sid][i]) pierw[i]=bs(0,deq.size()-1,t[i].se);
        else{
            while(deq.size() and deq.back().fi<=ff[i]) deq.pop_back();
            deq.push_back({ff[i],i});
        }
    }
    ll a1=0;
    int a2=0;
    for(int i=1;i<=n;i++) if(akt[sid][i]==1 or bi[sid][i]) a1+=(ll)t[i].fi,a2++;
    cout<<a2<<" "<<a1<<"\n";
    for(int i=1;i<=n;i++){
        if(akt[sid][i]==1 or akt[sid][i]==-1 or !bi[sid][i]) continue;
        if(pierw[i]==-1) s.insert({{(a2-1)*(-1),a1-t[i].fi},++wsk});
        else s.insert({{a2*(-1),a1-(ll)t[i].fi+(ll)t[pierw[i]].fi},++wsk});
        pop[wsk]=sid,kt[wsk]=i;
    }
}
void solve(){
    int k;
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>t[i].fi>>t[i].se;
    sort(t+1,t+1+n,[](pair<int,int> a,pair<int,int> b){
        if(a.fi==b.fi) return a.se>b.se;
        return a.fi<b.fi;
    });
    wsk=1,wsk2=1;
    cnt(1,1);
    while(s.size()){
        auto it=s.begin();
        pair<pair<int,ll>,int> curr=*it;
        s.erase(it); 
        ++wsk2;
        if(wsk2==k+1) return;
        cnt(wsk2,curr.se);
    }
}
int main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    int tt=1;
    while(tt--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 500 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 372 KB Output is correct
8 Correct 2 ms 368 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 500 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 372 KB Output is correct
8 Correct 2 ms 368 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 3 ms 592 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 8916 KB Output is correct
2 Correct 70 ms 8860 KB Output is correct
3 Correct 65 ms 8940 KB Output is correct
4 Correct 67 ms 8840 KB Output is correct
5 Correct 76 ms 9380 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 75 ms 9036 KB Output is correct
8 Correct 62 ms 8304 KB Output is correct
9 Correct 66 ms 8940 KB Output is correct
10 Correct 3 ms 712 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 64 ms 8548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 852 KB Output is correct
2 Correct 6 ms 852 KB Output is correct
3 Correct 6 ms 900 KB Output is correct
4 Correct 6 ms 836 KB Output is correct
5 Correct 6 ms 980 KB Output is correct
6 Correct 5 ms 852 KB Output is correct
7 Correct 7 ms 832 KB Output is correct
8 Correct 6 ms 840 KB Output is correct
9 Correct 6 ms 832 KB Output is correct
10 Correct 6 ms 840 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 5 ms 836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 500 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 372 KB Output is correct
8 Correct 2 ms 368 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 3 ms 592 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 596 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 3 ms 596 KB Output is correct
37 Correct 1 ms 324 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 68 ms 8916 KB Output is correct
41 Correct 70 ms 8860 KB Output is correct
42 Correct 65 ms 8940 KB Output is correct
43 Correct 67 ms 8840 KB Output is correct
44 Correct 76 ms 9380 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 75 ms 9036 KB Output is correct
47 Correct 62 ms 8304 KB Output is correct
48 Correct 66 ms 8940 KB Output is correct
49 Correct 3 ms 712 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 64 ms 8548 KB Output is correct
53 Correct 6 ms 852 KB Output is correct
54 Correct 6 ms 852 KB Output is correct
55 Correct 6 ms 900 KB Output is correct
56 Correct 6 ms 836 KB Output is correct
57 Correct 6 ms 980 KB Output is correct
58 Correct 5 ms 852 KB Output is correct
59 Correct 7 ms 832 KB Output is correct
60 Correct 6 ms 840 KB Output is correct
61 Correct 6 ms 832 KB Output is correct
62 Correct 6 ms 840 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 5 ms 836 KB Output is correct
66 Correct 793 ms 17108 KB Output is correct
67 Correct 1088 ms 16312 KB Output is correct
68 Correct 1048 ms 20120 KB Output is correct
69 Correct 988 ms 16440 KB Output is correct
70 Correct 1320 ms 32116 KB Output is correct
71 Correct 486 ms 15244 KB Output is correct
72 Correct 1152 ms 16548 KB Output is correct
73 Correct 1018 ms 15196 KB Output is correct
74 Correct 1172 ms 16960 KB Output is correct
75 Correct 1102 ms 46624 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 80 ms 10240 KB Output is correct