Submission #825981

#TimeUsernameProblemLanguageResultExecution timeMemory
825981vnm06Wiring (IOI17_wiring)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #include "wiring.h" using namespace std; struct polong long { long long ty; long long pos; polong long() {} polong long(long long a, long long b) { ty=a; pos=b; } }; bool cmp(polong long p, polong long q) { return p.pos<q.pos; } long long n; polong long t[200005]; long long ans[200005]; long long sp[200005]; long long pref[200005]; long long ri_r[200005], ri_b[200005]; long long val[200005]; long long id[800005]; void update(long long v, long long le, long long ri, long long pos, long long st) { if(ri<pos || le>pos) return; if(le==ri) { val[le]=st; id[v]=le; } else { long long mid=(le+ri)/2; update(2*v, le, mid, pos, st); update(2*v+1, mid+1, ri, pos, st); if(val[id[2*v]]<val[id[2*v+1]]) id[v]=id[2*v]; else id[v]=id[2*v+1]; } } long long query(long long v, long long le, long long ri, long long be, long long en) { if(ri<be || le>en) return -1; if(be<=le && ri<=en) return id[v]; else { long long mid=(le+ri)/2; long long id1=query(2*v, le, mid, be, en); long long id2=query(2*v+1, mid+1, ri, be, en); if(id1==-1) return id2; if(id2==-1) return id1; if(val[id1]<val[id2]) return id1; return id2; } } long long min_total_length(std::vector<int> r, std::vector<int> b) { n=r.size()+b.size(); for(long long i=0; i<r.size(); i++) t[i+1]=polong long(1, r[i]); for(long long i=0; i<b.size(); i++) t[i+r.size()+1]=polong long(0, b[i]); sort(t+1, t+n+1, cmp); long long idb=n+1, idr=n+1; for(long long i=1; i<=n; i++) pref[i]=pref[i-1]+t[i].pos; for(long long i=n; i>=1; i--) { long long ty=t[i].ty; if(ty==1) { if(idb==n+1) sp[i]=0; else sp[i]=t[idb].pos-t[i].pos; idr=i; } else { if(idr==n+1) sp[i]=0; else sp[i]=t[idr].pos-t[i].pos; idb=i; } } for(long long i=1; i<=n; i++) sp[i]+=sp[i-1]; for(long long i=1; i<=n; i++) update(1, 0, n+2, i, 1e18); update(1, 0, n+2, 0, 0); update(1, 0, n+2, 1, 1e18); ans[1]=1e18; long long le1=1, ri1=1; while(ri1+1<=n && t[ri1+1].ty==t[ri1].ty) { ri1++; ans[ri1]=1e18; update(1, 0, n+2, ri1, 1e18); } //cout<<n<<endl; for(long long j=ri1+1; j<=n; j++) { /////cout<<j<<" "; //cout<<j<<" c "<<le1<<" "<<ri1<<endl; if(t[j].ty!=t[j-1].ty && j!=ri1+1) { le1=ri1+1; ri1=j-1; } if(j-ri1>ri1-le1+1) { ans[j]=ans[j-1]+t[j].pos-t[ri1].pos; /// //cout<<j<<" "<<ans[j]<<" "<<ans[j]-sp[j]<<endl; update(1, 0, n+2, j, ans[j]-sp[j]); } else if(j-ri1==ri1-le1+1) { //cout<<j<<" tuka: "; ans[j]=min(ans[le1-1]+pref[j]-2*pref[ri1]+pref[le1-1], ans[le1]+pref[j]-2*pref[ri1]+pref[le1-1]); //cout<<j<<" "<<ans[j]<<" "<<ans[j]-sp[j]<<endl; //cout<<ans[le1-1]+pref[j]-2*pref[ri1]+pref[le1-1]<<" "<<ans[le1]+pref[j]-2*pref[ri1]+pref[le1-1]<<endl; update(1, 0, n+2, j, ans[j]-sp[j]); } else { ans[j]=ans[j-1]+t[j].pos-t[ri1].pos; long long tid=query(1, 0, n+2, le1-1, ri1-j+ri1); //cout<<ans[j]<<" "<<tid<<endl; long long calc2=ans[tid]; //cout<<calc2<<" "; tid++; calc2+=t[ri1+1].pos*(ri1-tid-(j-(ri1+1))); //cout<<calc2<<" "; calc2+=pref[j]-2*pref[ri1]+pref[tid-1]; //cout<<calc2<<endl; if(calc2<ans[j]) ans[j]=calc2; //cout<<j<<" "<<ans[j]<<" "<<ans[j]-sp[j]<<endl; update(1, 0, n+2, j, ans[j]-sp[j]); } //cout<<ans[j]<<endl; } return ans[n]; }

Compilation message (stderr)

wiring.cpp:6:1: error: expected unqualified-id before '{' token
    6 | {
      | ^
wiring.cpp:17:17: error: 'long' specified with 'polong'
   17 | bool cmp(polong long p, polong long q)
      |                 ^~~~
wiring.cpp:17:32: error: 'long' specified with 'polong'
   17 | bool cmp(polong long p, polong long q)
      |                                ^~~~
wiring.cpp:17:22: error: 'p' has incomplete type
   17 | bool cmp(polong long p, polong long q)
      |          ~~~~~~~~~~~~^
wiring.cpp:5:8: note: forward declaration of 'struct polong'
    5 | struct polong long
      |        ^~~~~~
wiring.cpp:17:37: error: 'q' has incomplete type
   17 | bool cmp(polong long p, polong long q)
      |                         ~~~~~~~~~~~~^
wiring.cpp:5:8: note: forward declaration of 'struct polong'
    5 | struct polong long
      |        ^~~~~~
wiring.cpp:23:8: error: 'long' specified with 'polong'
   23 | polong long t[200005];
      |        ^~~~
wiring.cpp:23:13: error: elements of array 'polong t [200005]' have incomplete type
   23 | polong long t[200005];
      |             ^
wiring.cpp:23:13: error: storage size of 't' isn't known
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:69:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     for(long long i=0; i<r.size(); i++) t[i+1]=polong long(1, r[i]);
      |                        ~^~~~~~~~~
wiring.cpp:69:55: error: expected primary-expression before 'long'
   69 |     for(long long i=0; i<r.size(); i++) t[i+1]=polong long(1, r[i]);
      |                                                       ^~~~
wiring.cpp:70:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for(long long i=0; i<b.size(); i++) t[i+r.size()+1]=polong long(0, b[i]);
      |                        ~^~~~~~~~~
wiring.cpp:70:64: error: expected primary-expression before 'long'
   70 |     for(long long i=0; i<b.size(); i++) t[i+r.size()+1]=polong long(0, b[i]);
      |                                                                ^~~~