답안 #197687

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197687 2020-01-22T10:10:14 Z ksmzzang2003 Bulldozer (JOI17_bulldozer) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld ;
typedef pair <ll,ll> pll ;
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define MAXN 5003
const ll llinf = 0x3f3f3f3f3f3f3f3f;
struct po
{
    ll x,y; ll co;
    bool operator <(po &r)
    {
        return pll(x,y) < pll(r.x,r.y);
    }
}arr[MAXN];

struct line
{
    ll i,j;
    long double a;
    line(int i,int j,ld a):i(i),j(j),a(a){}
    bool operator<(line &r)
    {
        return a>r.a;
    }
};
vector <line>  larr;
ll N;
struct node
    {
        ll lsum,rsum,sum,ans;
        node()
        {
            lsum = rsum = sum = ans  =0 ;
        }
        node(ll l,ll r,ll s,ll a)
        {
            lsum  = l; rsum =r; sum =s ; ans = a;
        }
    };
struct seg
{
    node tree[5003*4];
    node merge(node l,node r)
    {
        node ret;
        ret.lsum = max(l.lsum,l.sum + r.lsum);
        ret.rsum = max(r.rsum ,l.rsum + r.sum);
        ret.sum  = l.sum + r.sum;
        ret.ans = max({l.ans,r.ans,ret.sum,l.rsum + r.lsum});
        return ret;
    }
    node query(ll nodE,ll ns,ll ne,ll s,ll e)
    {
        if(e<ns || ne <s ) return node(-llinf,-llinf,0,-llinf);
        if(s<=ns &&ne <=e) return tree[nodE];
        return merge(query(nodE*2,ns,ns + ne >>1 ,s,e),query(nodE*2+1,(ns+ne>>1) + 1,ne,s,e));
    }
    void update(ll nodE,ll ns,ll ne,ll id,node k)
    {
        if(ne < id || id < ns) return;
        if(ns == ne)
        {
            tree[nodE] = k;
            return ;
        }
        update(nodE*2,ns,(ns+ne)/2,id,k);
        update(nodE*2+1,(ns+ne)/2+1,ne,id,k);
        tree[nodE] = merge(tree[nodE*2],tree[nodE*2+1]);
    }
}SEG;
int index[5003];
int main(){
    scanf("%lld",&N);
    for(ll i=1;i<=N;i++) scanf("%lld %lld %lld", &arr[i].x,&arr[i].y,&arr[i].co);
    sort(arr+1,arr+1+N);
    for(ll i=1;i<=N;i++)
    {
        for(ll j=i+1;j<=N;j++)
        {
            long double deltax = (ld)arr[i].x - arr[j].x;
            long double deltay = (ld)arr[i].y - arr[j].y;
            if(deltax==0) deltay = deltax>=0? 1e-18 : -1e-18;
            larr.eb(i,j,deltay/deltax);
        }
    }
    sort(larr.begin(),larr.end());
    for(ll i=1;i<=N;i++)
    {
        ll C = arr[i].co;
        SEG.update(1,1,N,i,node(C,C,C,C));
    }
    ll res = SEG.query(1,1,N,1,N).ans;
    for(int i=1;i<=N;i++) index[i] =i ;
    for(auto it : larr)
    {
        ll l = it.i, r = it.j ;
        node x = SEG.query(1,1,N,index[l],index[l]);
        node y = SEG.query(1,1,N,index[r],index[r]);
        SEG.update(1,1,N,index[r],x);
        SEG.update(1,1,N,index[l],y);
        swap(index[l],index[r]);
        res = max(res,SEG.query(1,1,N,1,N).ans);
    }
    printf("%lld",res);
}

Compilation message

bulldozer.cpp: In member function 'node seg::query(ll, ll, ll, ll, ll)':
bulldozer.cpp:60:41: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         return merge(query(nodE*2,ns,ns + ne >>1 ,s,e),query(nodE*2+1,(ns+ne>>1) + 1,ne,s,e));
                                      ~~~^~~~
bulldozer.cpp:60:74: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         return merge(query(nodE*2,ns,ns + ne >>1 ,s,e),query(nodE*2+1,(ns+ne>>1) + 1,ne,s,e));
                                                                        ~~^~~
bulldozer.cpp: At global scope:
bulldozer.cpp:75:15: error: 'int index [5003]' redeclared as different kind of symbol
 int index[5003];
               ^
In file included from /usr/include/c++/7/cstring:42:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:48,
                 from bulldozer.cpp:1:
/usr/include/string.h:477:1: note: previous declaration 'const char* index(const char*, int)'
 index (const char *__s, int __c) __THROW
 ^~~~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:97:34: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
     for(int i=1;i<=N;i++) index[i] =i ;
                                  ^
bulldozer.cpp:101:41: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
         node x = SEG.query(1,1,N,index[l],index[l]);
                                         ^
bulldozer.cpp:101:50: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
         node x = SEG.query(1,1,N,index[l],index[l]);
                                                  ^
bulldozer.cpp:102:41: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
         node y = SEG.query(1,1,N,index[r],index[r]);
                                         ^
bulldozer.cpp:102:50: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
         node y = SEG.query(1,1,N,index[r],index[r]);
                                                  ^
bulldozer.cpp:103:33: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
         SEG.update(1,1,N,index[r],x);
                                 ^
bulldozer.cpp:104:33: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
         SEG.update(1,1,N,index[l],y);
                                 ^
bulldozer.cpp:105:21: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
         swap(index[l],index[r]);
                     ^
bulldozer.cpp:105:30: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
         swap(index[l],index[r]);
                              ^
bulldozer.cpp:77:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&N);
     ~~~~~^~~~~~~~~~~
bulldozer.cpp:78:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(ll i=1;i<=N;i++) scanf("%lld %lld %lld", &arr[i].x,&arr[i].y,&arr[i].co);
                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~