Submission #1107602

#TimeUsernameProblemLanguageResultExecution timeMemory
1107602modwweDesignated Cities (JOI19_designated_cities)C++17
16 / 100
175 ms71600 KiB
#pragma GCC optimize("Ofast,unroll-loops") //#pragma GCC optimize("conserve-stack") #include<bits/stdc++.h> #define int long long #define ll long long #define down cout<<'\n'; #define debug cout<<" cucuucucuuu",down #define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0); #define modwwe int t;cin>>t; while(t--) #define bit(i,j) (i>>j&1) #define sobit(a) __builtin_popcountll(a) #define task "test" #define fin(x) freopen(x".inp","r",stdin) #define fou(x) freopen(x".ans","w",stdout) #define pb push_back #define mask(i) (1<<i) #define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms"; using namespace std; #define getchar_unlocked getchar inline int scan() { char c = getchar_unlocked(); int x = 0; while (c < '0' || c > '9') { c = getchar_unlocked(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + c - '0'; c = getchar_unlocked(); } return x; }; void phongbeo(); const int inf = 1e18; const int mod2 = -1e9+7; const int mod1 = 998244353; const int base=67; int add(int x,int y) { if(x+y>=mod2) x-=mod2; if(x+y<0) x+=mod2; return x+y; } struct icd { int c,d; }; struct ib { int a; int b; }; struct ic { int a, b, c; }; struct id { int a,b,c,d; }; struct ie { int a, b, c, d, e; }; int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center; int i, s10, s12,k1,k2,k3,s11,limit,w,l,r,last,root,cost; int kk; int el = 19; main() { if(fopen(task".inp","r")) { fin(task); // fou(task); } NHP /// cin>>s1; // modwwe phongbeo(),down // checktime } vector<int> v[200001]; int par[200001]; id a[200001]; ic dp[200001][3][2]; icd c[200001]; void dfs(int x,int y) { par[x]=y; for(auto f:v[x]) if(f!=y) dfs(f,x); } namespace sub5 { ///ta nhan xet la dinh cua canh x con lon nhat =dinh cua canh x+1 con lon nhat struct IT { ib t[800001]; int t2[800001]; ib mer(ib a,ib b) { if(a.a>=b.a) return a; return b; } void ff(int x) { for(int i=x*2; i<=x*2+1; i++) { t[i].a-=t2[x]; t2[i]+=t2[x]; } t2[x]=0; } void upd(int node,int l,int r,int l1,int r1,int x)/// find minimum cost { if(l>r1||r<l1) return; if(l>=l1&&r<=r1) { t[node].a-=x; t2[node]+=x; return; } int mid=l+r>>1; if(t2[node]!=0) ff(node); upd(node<<1,l,mid,l1,r1,x); upd(node<<1|1,mid+1,r,l1,r1,x); t[node]=mer(t[node<<1],t[node<<1|1]); } };///->t1=minimum new cost ic mer(ic a,ic b) { if(a.b<b.b) swap(a.a,b.a); return {a.a+b.a,a.b,max({a.c,b.c,b.b})}; } void dfs2(int x,int y) { dp[x][0][0]= {0,0,0}; for(auto f:v[x]) { if(f!=y) { dfs2(f,x); ///.b .c luu 2 con dc lay ///.a la luu cost for(int i=0; i<=2; i++) for(int j=0; j<2; j++) dp[x][i][j].a+=dp[f][0][0].a+c[f].c; for(int i=1; i<=2; i++) { if(dp[f][i][1].a+c[f].d+dp[x][0][0].a-dp[f][0][0].a-c[f].c<dp[x][i][1].a) dp[x][i][1]=dp[f][i][1], dp[x][i][1].a+=c[f].d+dp[x][0][0].a-dp[f][0][0].a-c[f].c; } for(int i=2; i>=0; --i) for(int j=0; j<=2; j++) if(i+j<=2) { if(dp[x][i+j][0].a>dp[x][i][0].a+dp[f][j][0].a+(j==0)*c[f].c-c[f].c-dp[f][0][0].a) dp[x][i+j][0]=mer(dp[x][i][0],dp[f][j][0]), dp[x][i+j][0].a+=(j==0)*c[f].c-c[f].c-dp[f][0][0].a; if(i>0&&j>0) if(dp[x][i+j][1].a>dp[x][i][0].a+dp[f][j][0].a+(j==0)*c[f].c-c[f].c-dp[f][0][0].a) dp[x][i+j][1]=mer(dp[x][i][0],dp[f][j][0]), dp[x][i+j][1].a+=(j==0)*c[f].c-c[f].c-dp[f][0][0].a; } } } for(int i=1; i>=0; i--) { if(dp[x][i+1][0].a>dp[x][i][0].a)dp[x][i+1][0]=mer({0,i,0},dp[x][i][0]); if(dp[x][i+1][1].a>dp[x][i][0].a)dp[x][i+1][1]=mer({0,i,0},dp[x][i][0]); } } void solve() { for(int i=1; i<n; i++) cin>>a[i].a>>a[i].b>>a[i].c>>a[i].d, v[a[i].a].pb(a[i].b), v[a[i].b].pb(a[i].a); dfs(1,0); for(int i=1; i<n; i++) { if(par[a[i].a]==a[i].b) swap(a[i].c,a[i].d),swap(a[i].a,a[i].b); c[a[i].b]= {a[i].c,a[i].d}; } for(int i=1; i<=n; i++) for(int j=0; j<=2; j++) for(int f=0; f<2; f++) dp[i][j][f]= {inf,0,0}; dfs2(1,0); cin>>m; for(int i=1; i<=m; i++) { cin>>l; cout<<dp[1][l][1].a,down } } } void phongbeo() { cin>>n; sub5::solve(); }

Compilation message (stderr)

designated_cities.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   75 | main()
      | ^~~~
designated_cities.cpp: In member function 'void sub5::IT::upd(long long int, long long int, long long int, long long int, long long int, long long int)':
designated_cities.cpp:130:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  130 |         int mid=l+r>>1;
      |                 ~^~
designated_cities.cpp: In function 'int main()':
designated_cities.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define fin(x) freopen(x".inp","r",stdin)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~
designated_cities.cpp:79:9: note: in expansion of macro 'fin'
   79 |         fin(task);
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...