제출 #1368380

#제출 시각아이디문제언어결과실행 시간메모리
1368380vjudge1크레이피쉬 글쓰는 기계 (IOI12_scrivener)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define inf 2e18
#define endl '\n'
const int N=5e5+2,MAXN=1e6+2;
int n,q,a[N],offset=1;
int seg[N*2+3],lazy[N*2];
void prop(int node,int l,int r){
    if(lazy[node]!=0){
        int mid=(l+r)/2;
        seg[node*2]+=lazy[node];
        seg[node*2+1]+=lazy[node];
        lazy[node*2]+=lazy[node];
        lazy[node*2+1]+=lazy[node];
        lazy[node]=0;
    }
}
void update(int node,int qlo,int qhi,int lo,int hi,int val){
    if(lo>=qlo && hi<=qhi){
        lazy[node]+=val;
        seg[node]+=val;
        return;
    }
    if(lo>qhi || hi<qlo)return;
    prop(node,lo,hi);
    int mid=(lo+hi)/2;
    update(node*2,qlo,qhi,lo,mid,val);
    update(node*2+1,qlo,qhi,mid+1,hi,val);
    seg[node]=max(seg[node*2],seg[node*2+1]);
}
int query(int node,int qlo,int qhi,int lo,int hi){
    if(lo>=qlo && hi<=qhi){
        return seg[node];
    }
    if(lo>qhi || hi<qlo)return 0;
    prop(node,lo,hi);
    int mid=(lo+hi)/2;
    int x=query(node*2,qlo,qhi,lo,mid),y=query(node*2+1,qlo,qhi,mid+1,hi);
    seg[node]=max(x,y);
    return seg[node];
}
signed main(){
    //srand(time(NULL))
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,k; cin>>n>>k;
    while(offset<n)offset*=2;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    map<int,int> last;
    for(int i=1;i<=k;i++){
        vector<int> v;
        v.pb(query(1,0,0,0,offset-1));
        for(int j=1;j<=n;j++){
            if(last[a[j]]==0){
                update(1,0,j-1,0,offset-1,1);
            }
            else{
                update(1,last[a[j]],j-1,0,offset-1,1);
            }
            last[a[j]]=j;
            int whattheflip=query(1,0,j-1,0,offset-1);
            v.pb(whattheflip);
        }
        for(int j=0;j<=N*2;j++){
            seg[j]=0;
            lazy[j]=0;
        }
        for(int j=0;j<v.size();j++){
            update(1,j,j,0,offset-1,v[j]);
            if(j==v.size()-1 && i==k)cout<<v[j];
        }
        last.clear();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

scrivener.cpp: In function 'int main()':
scrivener.cpp:69:20: warning: iteration 1000004 invokes undefined behavior [-Waggressive-loop-optimizations]
   69 |             lazy[j]=0;
      |             ~~~~~~~^~
scrivener.cpp:67:22: note: within this loop
   67 |         for(int j=0;j<=N*2;j++){
      |                     ~^~~~~
scrivener.cpp:69:20: warning: 'void* __builtin_memset(void*, int, long unsigned int)' writing 8000040 bytes into a region of size 8000032 overflows the destination [-Wstringop-overflow=]
   69 |             lazy[j]=0;
      |             ~~~~~~~^~
scrivener.cpp:9:16: note: destination object 'lazy' of size 8000032
    9 | int seg[N*2+3],lazy[N*2];
      |                ^~~~
/usr/bin/ld: /tmp/ccJjxP0j.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cck19XYT.o:scrivener.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccJjxP0j.o: in function `main':
grader.cpp:(.text.startup+0x6e): undefined reference to `Init()'
/usr/bin/ld: grader.cpp:(.text.startup+0x109): undefined reference to `TypeLetter(char)'
/usr/bin/ld: grader.cpp:(.text.startup+0x16d): undefined reference to `UndoCommands(int)'
/usr/bin/ld: grader.cpp:(.text.startup+0x199): undefined reference to `GetLetter(int)'
collect2: error: ld returned 1 exit status