제출 #964843

#제출 시각아이디문제언어결과실행 시간메모리
964843Ahmed57팀들 (IOI15_teams)C++17
컴파일 에러
0 ms0 KiB
#include "bits/stdc++.h" using namespace std; int NODES = 0; int L[3000001],R[3000001],ST[3000001]; int newleaf(int val){ NODES++; L[NODES] = -1; R[NODES] = -1; ST[NODES] = val; return NODES; } int newparent(int l,int r){ NODES++; L[NODES] = l; R[NODES] = r; ST[NODES] = ST[l]+ST[r]; return NODES; } int build(int l,int r){ if(l==r)return newleaf(0); int md = (l+r)/2; return newparent(build(l,md),build(md+1,r)); } int update(int p,int l,int r,int idx){ if(l==r)return newleaf(1+ST[p]); int md = (l+r)/2; if(idx<=md)return newparent(update(L[p],l,md,idx),R[p]); else return newparent(L[p],update(R[p],md+1,r,idx)); } int query(int p1,int p2,int l,int r,int lq,int rq){ if(l>=lq&&r<=rq){ return ST[p2]-ST[p1]; } if(r<lq||l>rq)return 0; int md = (l+r)/2; return query(L[p1],L[p2],l,md,lq,rq)+query(R[p1],R[p2],md+1,r,lq,rq); } int root[100001],n; vector<pair<int,int>> v; void init(int N,int A[],int B[]){ n = N; for(int i = 0;i<N;i++){ v.push_back({A[i],B[i]}); } sort(v.begin(),v.end()); root[0] = build(1,n); for(int i = 1;i<=v.size();i++){ root[i] = update(root[i-1],1,n,v[i-1].second); } } int w(int a,int b){ int it = lower_bound(v.begin(),v.end(),make_pair(a+1,0))-v.begin(); int it2 = lower_bound(v.begin(),v.end(),make_pair(b+1,0))-v.begin(); return query(root[it],root[it2],1,n,b,n); } bool can(int m,int k[]){ vector<int> K; K.push_back(0); for(int i = 0;i<m;i++){ K.push_back(k[i]); } sort(K.begin(),K.end()); long long dp[m+1]; dp[0] =0; for (int x=1; x <= m; x++) { dp[x] = 1e9; for(int i = 0;i<x;i++){ dp[x] = min(dp[x],dp[i]+w(K[i],K[x])-K[x]); } } for(int i = 1;i<=m;i++){ if(dp[i]<0)return 0; } return 1; } int main(){ int n; cin>>n; int A[n],B[n]; for(int i = 0;i<n;i++)cin>>A[i]>>B[i]; init(n,A,B); int q;cin>>q; while(q--){ int k;cin>>k; int lol[k]; for(int i = 0;i<k;i++)cin>>lol[i]; cout<<can(k,lol)<<endl; } }

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

teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i = 1;i<=v.size();i++){
      |                   ~^~~~~~~~~~
teams.cpp: In function 'int w(int, int)':
teams.cpp:52:61: warning: conversion from '__gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   52 |     int it = lower_bound(v.begin(),v.end(),make_pair(a+1,0))-v.begin();
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
teams.cpp:53:62: warning: conversion from '__gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   53 |     int it2 = lower_bound(v.begin(),v.end(),make_pair(b+1,0))-v.begin();
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
teams.cpp: In function 'int main()':
teams.cpp:77:9: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   77 |     int n;
      |         ^
teams.cpp:38:18: note: shadowed declaration is here
   38 | int root[100001],n;
      |                  ^
/usr/bin/ld: /tmp/ccTqGQjE.o: in function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'; /tmp/ccg6sHlG.o:teams.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status