Submission #1655141
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<--------------------
struct BIT {
int n;
vector<int> data;
BIT(int n_) {
n=n_;
data.resize(n,0);
}
void add(int i,int x) {
while(i<=n) {
data[i]+=x;
i+=i&-i;
}
}
int getsum(int r) {
int ret=0;
while(r>0) {
ret+=data[r];
r-=r&-r;
}
return ret;
}
};
signed main() {
int Q;
cin>>Q;
BIT bit(200005);
while(Q--) {
int t,x;
cin>>t>>x;
if(t==1) {
bit.add(x,1);
} else {
int L=0,R=200005;
while(R-L>1) {
int M=(L+R)/2;
int cnt=bit.getsum(M);
if(cnt>=x) {
R=M;
} else {
L=M;
}
}
cout<<R<<endl;
bit.add(R,-1);
}
}
return 0;
}
Submission Info
Submission Time |
|
Task |
C - データ構造 |
User |
algon |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
2593 Byte |
Status |
AC |
Exec Time |
78 ms |
Memory |
2432 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
100 / 100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt |
All |
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, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
AC |
2 ms |
1792 KB |
sample_02.txt |
AC |
2 ms |
1792 KB |
subtask1_01.txt |
AC |
2 ms |
1792 KB |
subtask1_02.txt |
AC |
2 ms |
1792 KB |
subtask1_03.txt |
AC |
2 ms |
1792 KB |
subtask1_04.txt |
AC |
7 ms |
1920 KB |
subtask1_05.txt |
AC |
14 ms |
1920 KB |
subtask1_06.txt |
AC |
2 ms |
1792 KB |
subtask1_07.txt |
AC |
36 ms |
2048 KB |
subtask1_08.txt |
AC |
78 ms |
2432 KB |
subtask1_09.txt |
AC |
78 ms |
2432 KB |
subtask1_10.txt |
AC |
57 ms |
2176 KB |
subtask1_11.txt |
AC |
57 ms |
2176 KB |
subtask1_12.txt |
AC |
34 ms |
1792 KB |
subtask1_13.txt |
AC |
78 ms |
2432 KB |
subtask1_14.txt |
AC |
76 ms |
2432 KB |
subtask1_15.txt |
AC |
60 ms |
2432 KB |
subtask1_16.txt |
AC |
50 ms |
2176 KB |