Submission #28023

#TimeUsernameProblemLanguageResultExecution timeMemory
28023noobprogrammerTeams (IOI15_teams)C++14
0 / 100
583 ms102256 KiB
#include "teams.h" #include <bits/stdc++.h> using namespace std ; #define ii pair<int,int> #define fi first #define se second #define vi vector<int> #define vii vector<ii> typedef long long ll ; int st[10000010] , le[1000010] , r[10000010] , n , qs[500010] , rt[500010] , ncnt = 1 ; vii srt ; void upd(int prev , int node , int f , int l ,int x){ if(f == l){ st[node] = st[prev] + 1 ; return ; } int mid = (f+l)>>1 ; if(mid < x){ le[node] = le[prev] ; r[node] = ncnt++ ; upd( r[prev] , r[node] , mid+1 , l , x ) ; } else{ le[node] = ncnt++ ; r[node] = r[prev] ; upd( le[prev] , le[node] , f , mid , x ) ; } st[node] = st[le[node]] + st[r[node]] ; } int qr(int prev , int node , int f ,int l , int x ){ if(x == 0) return 0 ; if(x >= l) return st[node] - st[prev] ; int mid = (f+l)>>1 ; if(mid < x) return st[le[node]] - st[le[prev]] + qr(r[prev] , r[node] , mid+1 , l , x ) ; else return qr(le[prev] , le[node] , f , mid , x ) ; } void init(int N, int A[], int B[]) { n = N ; for(int i=0;i<n;i++) { qs[A[i]]++ ; qs[B[i]+1]-- ; srt.push_back( { B[i] + 1 , i } ) ; } sort(srt.begin() , srt.end() ) ; for(int i=1;i<=n;i++) qs[i] += qs[i-1] ; // printf("%d ", qs[i]) ; // cout << endl ; int j = 0 , tmp , num ; rt[0] = 0 ; for(int i=1;i<=n;i++){ rt[i] = rt[i-1] ; while( j<srt.size() && i >= srt[j].fi ) { // printf("%d %d\n" , srt[j].fi , srt[j].se) ; num = srt[j].se ; tmp = ncnt++ ; upd(rt[i] , tmp , 1 , n , A[num] ) ; rt[i] = tmp ; j++ ; } // for(int j=1 ; j<=n ;j++) printf("%d " , qr(rt[i-1] , rt[i] , 1 , n , j) ) ; // cout << endl ; } } int can(int m, int arr[]) { int sum = 0 ; for(int i=0;i<m;i++) { sum += arr[i] ; if(sum > n) return 0 ; } sort(arr , arr+m) ; int lst = 0 , mn = 0 ; // printf("--------\n") ; for(int i=0;i<m;i++){ mn = mn - qr(rt[lst] , rt[arr[i]] , 1 , n , lst ) ; if(mn < 0) printf("%d" , 1/0) ; // printf("%d %d\n" , mn , arr[i]) ; if(qs[arr[i]] - mn < arr[i]) return 0 ; mn += arr[i] ; lst = arr[i] ; } return 1; }

Compilation message (stderr)

teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:53:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while( j<srt.size() && i >= srt[j].fi ) {
           ^
teams.cpp: In function 'int can(int, int*)':
teams.cpp:77:29: warning: division by zero [-Wdiv-by-zero]
   if(mn < 0) printf("%d" , 1/0) ;
                             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...