This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <set>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <fstream>
#include <complex>
#include <stack>
#include <set>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define ll long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define cd complex<double>
#define ld long double
#define pld pair<ld,ld>
#define iii pair<ii,int>
using namespace std;
const ll INF = 1e9+10;
const int MAXN = 100*100*10+10;
int elimArray[MAXN];//means after the ith cell, elimArray[i] had been eliminated.
vector<ii> modifRange;
int prevBest[MAXN];
int nextBest[MAXN];
int GetBestPosition(int n,int c,int r,int* arr,int* ss,int* ee){
// first modify the range to their actual sizes;
// this step is O(n^2) for now. change to O(nlogn) later.
FOR(i,c){
int s = ss[i];
int e = ee[i];
int ctr = 0;
FORE(j,s,e){
ctr += elimArray[j];
}
modifRange.pb({s,e+ctr});
elimArray[s] += e-s;
}
// now for each position, find its closest left and right element greater than r;
// this step is already O(n)
int bestFound = -1;
FOR(i,n-1){
prevBest[i] = bestFound;
if(arr[i] > r)bestFound = i;
}
prevBest[n-1] = bestFound;
bestFound = n;
for(int i = n-2;i>=0;i--){
nextBest[i+1] = bestFound;
if(arr[i] > r)bestFound = i;
}
nextBest[0] = bestFound;
/*
FOR(i,n-1)cout << arr[i] << " ";cout << endl;
for(auto e: modifRange){
cout << e.ff << " " << e.ss << endl;
}
cout << endl;
FOR(i,n-1)cout << prevBest[i] << " ";cout << endl;
FOR(i,n-1)cout << nextBest[i] << " ";cout << endl;
*/
int mx = 0;
FOR(i,n){
int hit = 0;
for(auto e : modifRange){
if(e.ss < i or e.ff > i)continue;
else if(e.ff <= prevBest[i] or e.ss >= nextBest[i]+1){
break;
}
hit++;
}
//cout <<i << " " << hit << endl;
mx = max(mx,hit);
}
return mx;
}
int ma1in(){
int arr[4];
arr[0] = 1;
arr[1] = 0;
arr[2] = 2;
arr[3] = 4;
int s[3] = {1,0,0};
int e[3] = {3,1,1};
cout << GetBestPosition(5,3,3,arr,s,e) << endl;
}
Compilation message (stderr)
tournament.cpp: In function 'int ma1in()':
tournament.cpp:104:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |