Submission #1839255
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
before_main_function() {
#ifdef int
#undef INF
#define INF INFLL
#define stoi stoll
#endif
cin.tie(0);ios::sync_with_stdio(false);
cout<<setprecision(15)<<fixed;
#define endl "\n"
}
} before_main_function;
//------------------8<------------------------------------8<--------------------
// 1-indexed
struct BIT {
vector<int> dat;
int n;
BIT(int n_) {
n=n_;
dat=vector<int>(n,0);
}
void add(int i,int x) {
while(i<=n) {
dat[i]+=x;
i+=i&-i;
}
}
int sum(int i) {
int ret=0;
while(i>0) {
ret+=dat[i];
i-=i&-i;
}
return ret;
}
};
signed main() {
int N,K;
cin>>N>>K;
vector<int> x(N);
cin>>x;
vector<int> inv(N);
REP(i,N) {
inv[x[i]-1]=i;
}
BIT bit(N+1);
REP(i,K-1) {
bit.add(x[i],1);
}
REPF(i,K-1,N) {
bit.add(x[i],1);
int L=-1,R=N;
while(R-L>1) {
int M=(L+R)/2;
if(bit.sum(M+1)>=K) {
R=M;
} else {
L=M;
}
}
cout<<inv[R]+1<<endl;
}
return 0;
}
Submission Info
Submission Time |
|
Task |
B - 特別賞 |
User |
algon |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
2583 Byte |
Status |
AC |
Exec Time |
38 ms |
Memory |
3072 KB |
Judge Result
Set Name |
Sample |
Subtask1 |
Subtask2 |
Score / Max Score |
0 / 0 |
40 / 40 |
60 / 60 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt |
Subtask1 |
sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt |
Subtask2 |
sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
AC |
1 ms |
256 KB |
sample_02.txt |
AC |
1 ms |
256 KB |
subtask1_01.txt |
AC |
1 ms |
256 KB |
subtask1_02.txt |
AC |
1 ms |
256 KB |
subtask1_03.txt |
AC |
1 ms |
256 KB |
subtask1_04.txt |
AC |
1 ms |
256 KB |
subtask1_05.txt |
AC |
1 ms |
256 KB |
subtask1_06.txt |
AC |
1 ms |
256 KB |
subtask1_07.txt |
AC |
1 ms |
256 KB |
subtask1_08.txt |
AC |
1 ms |
256 KB |
subtask1_09.txt |
AC |
1 ms |
256 KB |
subtask1_10.txt |
AC |
1 ms |
256 KB |
subtask1_11.txt |
AC |
1 ms |
256 KB |
subtask2_01.txt |
AC |
6 ms |
640 KB |
subtask2_02.txt |
AC |
1 ms |
256 KB |
subtask2_03.txt |
AC |
31 ms |
2944 KB |
subtask2_04.txt |
AC |
38 ms |
3072 KB |
subtask2_05.txt |
AC |
12 ms |
2560 KB |
subtask2_06.txt |
AC |
25 ms |
2944 KB |
subtask2_07.txt |
AC |
28 ms |
2944 KB |
subtask2_08.txt |
AC |
27 ms |
2944 KB |
subtask2_09.txt |
AC |
29 ms |
2944 KB |