Submission #254801

# Submission time Handle Problem Language Result Execution time Memory
254801 2020-07-30T15:43:13 Z Mercenary Svjetlost (COI18_svjetlost) C++14
0 / 100
13 ms 2304 KB
#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]);
    }
}s;
ld dis(ii a , ii b){
    return sqrt((ll)(a.first - b.first) * (a.first - b.first) + (ll)(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;
        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);
    val.erase(unique(val.begin(),val.end(),is_equal) , val.end());
//    for(auto c : val)cout << c.first << " " << c.second << endl;
//    cout << endl;
    s.init(val.size() * 2);
    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;
//        swap(l,r);
        if(l < r){
            s.update(1,1,val.size() * 2,2* l+1,2 * r-1,delta);
        }else{
            s.update(1,1,val.size() * 2,l*2+1,val.size()*2,delta);
            s.update(1,1,val.size() * 2,1,r*2-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 << i << endl;
    }
    cout << fixed << setprecision(5);
    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

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:78: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:79: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 time Memory Grader output
1 Correct 0 ms 384 KB 11 numbers
2 Incorrect 1 ms 384 KB 1st numbers differ - expected: '34437.5563444541', found: '34024.7174900000', error = '0.0119880415'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB 11 numbers
2 Incorrect 1 ms 384 KB 1st numbers differ - expected: '34437.5563444541', found: '34024.7174900000', error = '0.0119880415'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB 1st numbers differ - expected: '32934.3604541195', found: '32228.4601700000', error = '0.0214335507'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 2304 KB 1st numbers differ - expected: '1042655967.3918291330', found: '1042441600.4061900377', error = '0.0002055970'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB 11 numbers
2 Incorrect 1 ms 384 KB 1st numbers differ - expected: '34437.5563444541', found: '34024.7174900000', error = '0.0119880415'
3 Halted 0 ms 0 KB -