제출 #574660

#제출 시각아이디문제언어결과실행 시간메모리
574660Theo830팀들 (IOI15_teams)C++17
0 / 100
365 ms249152 KiB
#include <bits/stdc++.h> using namespace std; typedef int ll; const ll INF = 1e9+7; const ll MOD = 998244353; typedef pair<ll,ll> ii; #define iii pair<ll,ii> #define ull unsigned ll #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define vll vector<ll> #define F first #define S second #define all(x) (x).begin(), (x).end() ///I hope I will get uprating and don't make mistakes ///I will never stop programming ///sqrt(-1) Love C++ ///Please don't hack me ///@TheofanisOrfanou Theo830 ///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst) ///Stay Calm ///Look for special cases ///Beware of overflow and array bounds ///Think the problem backwards ///Training //#include "teams.h" const ll sizz = 500005; vector<ii>arr; ll R[sizz]; ll posa[sizz] = {0}; ll vale[1000][25]; ll n; vll el; ll C = 0; vector<ll>seg[4 * sizz]; void build(ll s,ll e,ll idx){ if(s == e){ seg[idx].pb(arr[s-1].S); return; } ll mid = (s + e) / 2; build(s,mid,idx * 2); build(mid+1,e,idx * 2 + 1); ll p1 = 0,p2 = 0; while(p1 < seg[idx * 2].size() || p2 < seg[idx * 2 + 1].size()){ if(p1 == seg[idx * 2].size()){ seg[idx].pb(seg[idx * 2 + 1][p2]); p2++; } else if(p2 == seg[idx * 2 + 1].size()){ seg[idx].pb(seg[idx * 2][p1]); p1++; } else{ if(seg[idx * 2][p1] < seg[idx * 2 + 1][p2]){ seg[idx].pb(seg[idx * 2][p1]); p1++; } else{ seg[idx].pb(seg[idx * 2 + 1][p2]); p2++; } } } } void solve(ll l,ll r,ll L,ll R,ll idx){ if(l > r || L > R){ return; } ll mid = (l + r) / 2; ll pos = lower_bound(all(el),seg[idx][mid]) - el.begin(); if(pos != 0){ pos--; vale[pos][C] = min(vale[pos][C],mid); solve(l,mid - 1,L,pos,idx); solve(mid+1,r,pos+1,R,idx); } else{ solve(mid+1,r,pos,R,idx); } } void query(ll s,ll e,ll qs,ll qe,ll idx){ if(qs <= s && e <= qe){ vale[el.size()][C] = seg[idx].size(); solve(0,seg[idx].size() - 1,0,el.size() - 1,idx); C++; return; } if(s > qe || qs > e){ return; } ll mid = (s + e) / 2; query(s,mid,qs,qe,idx * 2); query(mid+1,e,qs,qe,idx * 2 + 1); } void init(int N, int A[], int B[]){ n = N; f(i,0,n){ arr.pb(ii(A[i],B[i])); } sort(all(arr)); ll pos = 1; for(auto x:arr){ R[x.F] = pos; pos++; } f(i,1,n+1){ R[i] = max(R[i],R[i-1]); } build(1,n,1); } int can(int M, int K[]) { ll sum = 0; vector<ii>ex; sort(K,K+M); f(i,0,M){ sum += K[i]; if(i > 0 && K[i] == K[i-1]){ ex.back().S++; } else{ ex.pb(ii(K[i],1)); } } if(sum > n){ return 0; } ll siz = ex.size(); f(i,0,siz){ posa[i] = 0; } ll l = 1; ll j = 0; el.clear(); for(auto x:ex){ el.pb(x.F - 1); } el.pb(INF); for(auto x:ex){ ll r = R[x.F]; f(i,j-1,siz + 2){ f(u,0,22){ vale[i][u] = n; } } C = 0; query(1,n,l,r,1); ll em = x.S * x.F; for(ll i = siz + 1;i >= j;i--){ f(u,0,C){ vale[i][u] = min(vale[i][u],vale[i+1][u]); posa[i] += vale[i+1][u] - vale[i][u]; } } f(i,j,siz){ ll E = min(posa[i],em); em -= E; posa[i] -= E; if(em == 0){ break; } } if(em > 0){ return 0; } l = r + 1; j++; } return 1; } /* int main() { int N; cin>>N; int *A = (int*)malloc(sizeof(int)*(unsigned int)N); int *B = (int*)malloc(sizeof(int)*(unsigned int)N); for (int i = 0; i < N; ++i) { cin>>A[i]>>B[i]; } init(N, A, B); int Q; cin>>Q; for (int i = 0; i < Q; ++i) { int M; cin>>M; int *K = (int*)malloc(sizeof(int)*(unsigned int)M); for (int j = 0; j < M; ++j) { cin>>K[j]; } printf("%d\n", can(M, K)); } return 0; } */ /* 4 2 4 1 2 2 3 2 3 2 2 1 3 2 1 1 */

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

teams.cpp: In function 'void build(ll, ll, ll)':
teams.cpp:45:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     while(p1 < seg[idx * 2].size() || p2 < seg[idx * 2 + 1].size()){
      |           ~~~^~~~~~~~~~~~~~~~~~~~~
teams.cpp:45:42: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     while(p1 < seg[idx * 2].size() || p2 < seg[idx * 2 + 1].size()){
      |                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
teams.cpp:46:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if(p1 == seg[idx * 2].size()){
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~
teams.cpp:50:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         else if(p2 == seg[idx * 2 + 1].size()){
      |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
teams.cpp: In function 'void solve(ll, ll, ll, ll, ll)':
teams.cpp:66:30: warning: declaration of 'R' shadows a global declaration [-Wshadow]
   66 | void solve(ll l,ll r,ll L,ll R,ll idx){
      |                           ~~~^
teams.cpp:29:4: note: shadowed declaration is here
   29 | ll R[sizz];
      |    ^
teams.cpp:71:49: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'll' {aka 'int'} may change value [-Wconversion]
   71 |     ll pos = lower_bound(all(el),seg[idx][mid]) - el.begin();
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
teams.cpp: In function 'void query(ll, ll, ll, ll, ll)':
teams.cpp:84:43: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'll' {aka 'int'} may change value [-Wconversion]
   84 |         vale[el.size()][C] = seg[idx].size();
      |                              ~~~~~~~~~~~~~^~
teams.cpp:85:33: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'll' {aka 'int'} may change value [-Wconversion]
   85 |         solve(0,seg[idx].size() - 1,0,el.size() - 1,idx);
      |                 ~~~~~~~~~~~~~~~~^~~
teams.cpp:85:49: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'll' {aka 'int'} may change value [-Wconversion]
   85 |         solve(0,seg[idx].size() - 1,0,el.size() - 1,idx);
      |                                       ~~~~~~~~~~^~~
teams.cpp: In function 'int can(int, int*)':
teams.cpp:128:18: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'll' {aka 'int'} may change value [-Wconversion]
  128 |  ll siz = ex.size();
      |           ~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...