Submission #1050169

# Submission time Handle Problem Language Result Execution time Memory
1050169 2024-08-09T07:49:23 Z vjudge1 Art Exhibition (JOI18_art) C++17
100 / 100
448 ms 47616 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
#define all(x) (x).begin(), (x).end()
#define f first
#define s second  
#define int long long 
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pb push_back
#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
int mod = 100000000;
typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;
const int N=1e6+150;
// int mind[N];
int d,n;
vector<int> t;
void init (int nn){
    d=nn;
	t.assign (d, 0);
}
int sum (int r){
	int result = 0;
	for (; r >= 0; r = (r & (r+1)) - 1)
		result += t[r];
	return result;
}

void inc (int i, int delta){
	for (; i < d; i = (i | (i+1)))
		t[i] += delta;
}

int sum (int l, int r){
	return sum (r) - sum (l-1);
}
int ans=0,sze=0,k;
vector<int>sz;
// vector<int>cnt;
vector<int>used;
vector<vector<int>>g;
void precalc(int v,int p){
    sz[v]=1;
    for(auto k:g[v]){
        if(k!=p and !used[k]){
            precalc(k,v);
            sz[v]+=sz[k];
        }
    }
    sze=max(sz[v],sze);
}
int centroid(int v,int p){
    for(auto k:g[v]){
        if(k!=p and sz[k]>sze/2 and !used[k]){
            return centroid(k,v);
        }
    }
    return v;
}
void dfs(int v,int p,int len){
    if(len>=d){
        return;
    }
    // cout<<v<<' '<<sum(k-len-1)<<" "<<sum(d-len)<<" "<<len<<' '<<sum(k-len,d-len)<<'\n';
    ans+=sum(k-len,d-len-1);
    for(auto to:g[v]){
        if(to!=p and !used[to]){
            dfs(to,v,len+1);
        }
    }
}
void update(int v,int p,int len){
    if(len>=d){
        return;
    }
    //cout<<k<<" "<<v<<" "<<len<<"\n";
   inc(len,1);
    //cout<<k<<" "<<v<<" "<<len<<" "<<cnt[len]<<"\n";
    for(auto to:g[v]){
        if(to!=p and !used[to]){
            update(to,v,len+1);
        }
    }
}
int h;
void cent(int v){
    sze=0;
    precalc(v,h);
    if(sze<=k)
        return;
    v=centroid(v,h);
    //cout<<v<<" ";
    inc(0,1);
    used[v]=1;
    // cout<<t[0]<<'\n';
    for(auto to:g[v]){
        if(to!=h and !used[to]){
            dfs(to,v,1);
            update(to,v,1);
        }
    }
    for(int i=0;i<d;i++){
        t[i]=0;
    }
    // cout<<sum(1,d)<<"\n";
    for(auto to:g[v]){
        if(to!=h and !used[to]){
            h=v;
            cent(to);
        }
    }
}
void solve(){
    int m,x,q,b=2,c=20,e=0,f=0,a=0,z;
    cin>>n;
    map<int,int>man;
    vector<pair<int,int>>v;
    for(int i=0;i<n;i++){
        cin>>e>>f;
        man[e]+=f;
    }
    e=0;
    f=0;
    for(auto k:man){
        v.pb({k.f,k.s});
    }
    n=v.size();
    vector<int>p1(n+1,0);
    vector<int>p2(n+1,0);
    int sum=0;
    for(int i=1;i<=n;i++){
        p1[i]=v[i-1].f-sum;
        sum+=v[i-1].s;
        // cout<<p1[i]<<" ";
    }
    cout<<'\n';
    sum=0;
    for(int i=1;i<=n;i++){
        sum+=v[i-1].s;
        p2[i]=sum-v[i-1].f;
        // cout<<p2[i]<<" ";
    }
    cout<<'\n';
    for(int i=1;i<=n;i++){
        e=max(p1[i],e);
        a=max(a,p2[i]+e);
    }
    cout<<a<<" ";
}

signed main(){
    ios::sync_with_stdio(0); 
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // precalc();
    // cin >> t;
    while(t--) {
        solve();
    }
}

Compilation message

art.cpp: In function 'void solve()':
art.cpp:115:9: warning: unused variable 'm' [-Wunused-variable]
  115 |     int m,x,q,b=2,c=20,e=0,f=0,a=0,z;
      |         ^
art.cpp:115:11: warning: unused variable 'x' [-Wunused-variable]
  115 |     int m,x,q,b=2,c=20,e=0,f=0,a=0,z;
      |           ^
art.cpp:115:13: warning: unused variable 'q' [-Wunused-variable]
  115 |     int m,x,q,b=2,c=20,e=0,f=0,a=0,z;
      |             ^
art.cpp:115:15: warning: unused variable 'b' [-Wunused-variable]
  115 |     int m,x,q,b=2,c=20,e=0,f=0,a=0,z;
      |               ^
art.cpp:115:19: warning: unused variable 'c' [-Wunused-variable]
  115 |     int m,x,q,b=2,c=20,e=0,f=0,a=0,z;
      |                   ^
art.cpp:115:36: warning: unused variable 'z' [-Wunused-variable]
  115 |     int m,x,q,b=2,c=20,e=0,f=0,a=0,z;
      |                                    ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 408 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 408 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 2 ms 884 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 748 KB Output is correct
33 Correct 2 ms 856 KB Output is correct
34 Correct 1 ms 860 KB Output is correct
35 Correct 2 ms 1112 KB Output is correct
36 Correct 2 ms 752 KB Output is correct
37 Correct 2 ms 860 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
39 Correct 2 ms 860 KB Output is correct
40 Correct 1 ms 860 KB Output is correct
41 Correct 2 ms 740 KB Output is correct
42 Correct 1 ms 860 KB Output is correct
43 Correct 1 ms 764 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 1 ms 860 KB Output is correct
46 Correct 2 ms 860 KB Output is correct
47 Correct 2 ms 860 KB Output is correct
48 Correct 2 ms 828 KB Output is correct
49 Correct 2 ms 860 KB Output is correct
50 Correct 2 ms 860 KB Output is correct
51 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 408 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 2 ms 884 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 748 KB Output is correct
33 Correct 2 ms 856 KB Output is correct
34 Correct 1 ms 860 KB Output is correct
35 Correct 2 ms 1112 KB Output is correct
36 Correct 2 ms 752 KB Output is correct
37 Correct 2 ms 860 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
39 Correct 2 ms 860 KB Output is correct
40 Correct 1 ms 860 KB Output is correct
41 Correct 2 ms 740 KB Output is correct
42 Correct 1 ms 860 KB Output is correct
43 Correct 1 ms 764 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 1 ms 860 KB Output is correct
46 Correct 2 ms 860 KB Output is correct
47 Correct 2 ms 860 KB Output is correct
48 Correct 2 ms 828 KB Output is correct
49 Correct 2 ms 860 KB Output is correct
50 Correct 2 ms 860 KB Output is correct
51 Correct 2 ms 860 KB Output is correct
52 Correct 335 ms 47284 KB Output is correct
53 Correct 305 ms 47184 KB Output is correct
54 Correct 310 ms 47580 KB Output is correct
55 Correct 311 ms 47284 KB Output is correct
56 Correct 327 ms 47284 KB Output is correct
57 Correct 303 ms 47284 KB Output is correct
58 Correct 308 ms 47280 KB Output is correct
59 Correct 334 ms 47568 KB Output is correct
60 Correct 396 ms 47280 KB Output is correct
61 Correct 408 ms 47336 KB Output is correct
62 Correct 400 ms 47616 KB Output is correct
63 Correct 448 ms 47544 KB Output is correct
64 Correct 441 ms 47312 KB Output is correct
65 Correct 352 ms 47396 KB Output is correct
66 Correct 393 ms 47276 KB Output is correct
67 Correct 347 ms 47280 KB Output is correct
68 Correct 328 ms 47280 KB Output is correct