제출 #887033

#제출 시각아이디문제언어결과실행 시간메모리
887033abcvuitunggio팀들 (IOI15_teams)C++17
100 / 100
1238 ms338072 KiB
#include "teams.h"
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
int n,cnt[500001],dp[1010],root[500001],st[40000001],le[40000001],ri[40000001],nNode,nRoot,R[500001],pos[500001];
vector <int> v[500001],ve,tmp;
int update(int node, int l, int r, int u, int v){
    int mid=(l+r)>>1,cur=++nNode;
    st[cur]=st[node];
    le[cur]=le[node];
    ri[cur]=ri[node];
    if (l>=u&&r<=v){
        st[cur]++;
        return cur;
    }
    if (u<=mid)
        le[cur]=update(le[node],l,mid,u,v);
    if (v>mid)
        ri[cur]=update(ri[node],mid+1,r,u,v);
    return cur;
}
void fakeget(int l=1, int r=n, int u=1, int v=ve.size()-1){
    if (u>v||ve[v]<l||ve[u]>r)
        return;
    if (l==r)
        return;
    int mid=(l+r)>>1;
    pos[mid]=upper_bound(ve.begin(),ve.end(),mid)-ve.begin();
    fakeget(l,mid,u,min(v,pos[mid]-1));
    fakeget(mid+1,r,max(pos[mid],u),v);
}
int get(int node, int l, int r, int u, int v){
    if (u>v||ve[v]<l||ve[u]>r)
        return -INF;
    if (l==r)
        return dp[u]-st[node];
    int mid=(l+r)>>1;
    return max(get(le[node],l,mid,u,min(v,pos[mid]-1)),get(ri[node],mid+1,r,max(pos[mid],u),v))-st[node];
}
void init(int N, int A[], int B[]){
    n=N;
    for (int i=0;i<n;i++)
        v[A[i]].push_back(B[i]);
    for (int i=n;i;i--){
        for (int j:v[i]){
            nRoot++;
            root[nRoot]=update(root[nRoot-1],1,n,i,j);
        }
        R[i]=root[nRoot];
    }
}
int can(int M, int K[]){
    int sum=0;
    for (int i=0;i<M;i++){
        sum+=K[i];
        cnt[K[i]]=0;
        if (sum>n)
            return 0;
    }
    ve={0};
    for (int i=0;i<M;i++){
        if (!cnt[K[i]])
            ve.push_back(K[i]);
        cnt[K[i]]+=K[i];
    }
    sort(ve.begin(),ve.end());
    fakeget();
    for (int i=ve.size()-1;i>=0;i--)
        dp[i]=max(get(R[ve[i]+1],1,n,i+1,ve.size()-1),0)+cnt[ve[i]];
    return (!dp[0]);
}

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

teams.cpp: In function 'int update(int, int, int, int, int)':
teams.cpp:7:47: warning: declaration of 'v' shadows a global declaration [-Wshadow]
    7 | int update(int node, int l, int r, int u, int v){
      |                                           ~~~~^
teams.cpp:6:14: note: shadowed declaration is here
    6 | vector <int> v[500001],ve,tmp;
      |              ^
teams.cpp: At global scope:
teams.cpp:22:56: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   22 | void fakeget(int l=1, int r=n, int u=1, int v=ve.size()-1){
      |                                               ~~~~~~~~~^~
teams.cpp: In function 'void fakeget(int, int, int, int)':
teams.cpp:22:45: warning: declaration of 'v' shadows a global declaration [-Wshadow]
   22 | void fakeget(int l=1, int r=n, int u=1, int v=ve.size()-1){
      |                                         ~~~~^~~~~~~~~~~~~
teams.cpp:6:14: note: shadowed declaration is here
    6 | vector <int> v[500001],ve,tmp;
      |              ^
teams.cpp:28:50: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   28 |     pos[mid]=upper_bound(ve.begin(),ve.end(),mid)-ve.begin();
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
teams.cpp: In function 'int get(int, int, int, int, int)':
teams.cpp:32:44: warning: declaration of 'v' shadows a global declaration [-Wshadow]
   32 | int get(int node, int l, int r, int u, int v){
      |                                        ~~~~^
teams.cpp:6:14: note: shadowed declaration is here
    6 | vector <int> v[500001],ve,tmp;
      |              ^
teams.cpp: In function 'int can(int, int*)':
teams.cpp:67:13: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   67 |     fakeget();
      |             ^
teams.cpp:68:25: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   68 |     for (int i=ve.size()-1;i>=0;i--)
      |                ~~~~~~~~~^~
teams.cpp:69:51: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   69 |         dp[i]=max(get(R[ve[i]+1],1,n,i+1,ve.size()-1),0)+cnt[ve[i]];
      |                                          ~~~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...