Submission #254816

#TimeUsernameProblemLanguageResultExecution timeMemory
254816MercenarySvjetlost (COI18_svjetlost)C++14
100 / 100
1731 ms108640 KiB
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> #define pb push_back #define mp make_pair #define taskname "A" using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef tree <ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; const int maxn = 1e5 + 5; const int mod = 1e9 + 7; ii operator - (const ii x , const ii y){ return mp(x.first - y.first , x.second - y.second); } ll operator * (const ii x , const ii y){ return (ll)x.first * y.second - (ll)x.second * y.first; } bool cmp(ii a, ii b){ if((a < mp(0,0)) != (b < mp(0,0)))return (a < mp(0,0)) < (b < mp(0,0)); return a * b > 0; } bool is_equal(ii a , ii b){ return !cmp(a,b) && !cmp(b,a); } vector<ii> val; ii a[maxn]; int n , m; int b[maxn]; int nxt[maxn] , pre[maxn]; struct seg{ vector<ld> s,lz; int n; void init(int _n){ n = _n; s.resize((n+5) * 4 , 0); lz.resize((n+5) * 4 , 0); } void push(int x , bool key){ s[x] += lz[x]; if(key){ lz[x * 2] += lz[x]; lz[x * 2 + 1] += lz[x]; } lz[x] = 0; } void update(int x , int l , int r , int L , int R , ld delta){ push(x,l!=r); if(L > r || l > R)return; if(L <= l && r <= R){ lz[x] += delta; push(x,l!=r); return; } int mid = l + r >> 1; update(x * 2 , l , mid , L , R ,delta); update(x * 2 + 1 , mid + 1 , r , L , R , delta); s[x] = max(s[x * 2] , s[x * 2 + 1]); } void update(int L , int R , ld delta){ update(1,1,n,L,R,delta); } }s; ld dis(ii a , ii b){ return sqrt((ld)(a.first - b.first) * (a.first - b.first) + (ld)(a.second - b.second) * (a.second - b.second)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP", "r",stdin); freopen(taskname".OUT", "w",stdout); } cin >> n; for(int i = 0 ; i < n ; ++i){ cin >> a[i].first >> a[i].second; nxt[i] = (i + 1 + n) % n; pre[i] = (i - 1 + n) % n; } for(int i = 0 ; i < n ; ++i){ val.pb(a[nxt[i]]-a[i]);val.pb(a[i]-a[nxt[i]]); } cin >> m; for(int i = 0 ; i < m ; ++i){ cin >> b[i];--b[i]; int u = b[i]; val.pb(a[nxt[u]]-a[pre[u]]); val.pb(a[pre[u]]-a[nxt[u]]); pre[nxt[u]] = pre[u]; nxt[pre[u]] = nxt[u]; } val.pb(mp(0,-1)); sort(val.begin(),val.end(),cmp); // for(auto c : val)cout << c.first << " " << c.second << endl; val.erase(unique(val.begin(),val.end(),is_equal) , val.end()); s.init(2 * val.size()); auto add = [&](ii a , ii b,ld delta){ int l = lower_bound(val.begin(),val.end(),a,cmp) - val.begin() + 1; int r = lower_bound(val.begin(),val.end(),b,cmp) - val.begin() + 1; assert(is_equal(val[l - 1],a)); // cout << a.first << " " << a.second << " " << l - 1 << endl; swap(l,r); if(l <= r){ s.update(2 * l + 1, 2 * r-1,delta); }else{ s.update(2 * l + 1, 2 * val.size(),delta); s.update(1 , 2 * r - 1 ,delta); } }; for(int i = 0 ; i < n ; ++i){ nxt[i] = (i + 1 + n) % n; pre[i] = (i - 1 + n) % n; add(a[nxt[i]]-a[i],a[i]-a[nxt[i]],dis(a[i],a[nxt[i]])); } cout << fixed << setprecision(6); cout << s.s[1] << '\n'; for(int i = 0 ; i < m ; ++i){ int u = b[i]; add(a[nxt[u]]-a[u] , a[u] - a[nxt[u]] , -dis(a[u],a[nxt[u]])); add(a[u]-a[pre[u]] , a[pre[u]] - a[u] , -dis(a[u],a[pre[u]])); add(a[nxt[u]]-a[pre[u]] , a[pre[u]] - a[nxt[u]] , dis(a[pre[u]],a[nxt[u]])); pre[nxt[u]] = pre[u]; nxt[pre[u]] = nxt[u]; cout << s.s[1] << '\n'; } }

Compilation message (stderr)

svjetlost.cpp: In member function 'void seg::update(int, int, int, int, int, ld)':
svjetlost.cpp:64:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = l + r >> 1;
                   ~~^~~
svjetlost.cpp: In function 'int main()':
svjetlost.cpp:81:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
svjetlost.cpp:82:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...