結果
| 問題 |
No.1471 Sort Queries
|
| コンテスト | |
| ユーザー |
carrot46
|
| 提出日時 | 2021-04-10 00:16:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 39 ms / 2,000 ms |
| コード長 | 3,151 bytes |
| コンパイル時間 | 3,364 ms |
| コンパイル使用メモリ | 210,212 KB |
| 最終ジャッジ日時 | 2025-01-20 15:22:19 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace atcoder;
//#pragma GCC optimize("O3")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
using tp = tuple<ll, ll, ll>;
const ll INF = (1LL<<61);
template<class T> bool chmin(T &a, const T b){
if(a > b) {a = b; return true;}
else return false;
}
template<class T> bool chmax(T &a, const T b){
if(a < b) {a = b; return true;}
else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
if(!v.empty()){
for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
std::cout<<v.back();
}
if(endline) std::cout<<std::endl;
}
template <class T> class BIT {
//T has operator "+=" and can be initialized with 0.
int n, n_2k;
vector<T> bitree;
public:
//make [0, n) BIT
BIT(int _n) : bitree(_n + 1, 0) {
n = n_2k = _n;
while(n_2k & (n_2k - 1)) n_2k &= n_2k - 1;
}
//BIT[id] += x
void add(int id, T x) {
++id;
while (id <= n) {
bitree[id] += x;
id += id & -id;
}
}
//sum of BIT[0, id]
T sum(int id) {
++id;
T temp(0);
while (id > 0) {
temp += bitree[id];
id -= id & -id;
}
return temp;
}
//sum of BIT[l, r)
T range_sum(int l, int r) {
return sum(r-1) - sum(l-1);
}
//return i in [0, n]
//i = argmin_{j} (BIT[0, j] >= x)
//T should have bool operator '<'
int lower_bound(T x){
int id = n_2k;
T temp(0);
for(int plus = id; plus; id |= (plus>>=1)){
if(id <= n && temp + bitree[id] < x) temp += bitree[id];
else id ^= plus;
}
return id;
}
};
struct query{
int id, l, r, x, lb, ub;
query(int a, int b, int c, int d, int e, int f)
: id(a), l(b), r(c), x(d), lb(e), ub(f){}
int cen(){return (ub + lb) / 2;}
};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin>>N>>Q>>S;
int _n = N;
vector<query> qs;
rep(i, Q){
int l, r, x;
cin>>l>>r>>x;
--l;
qs.emplace_back(i, l, r, x, -1, _n - 1);
}
vec ord(N);
iota(ALL(ord), 0);
sort(ALL(ord), [&](int x, int y){ return S[x] < S[y];});
while(_n){
auto q = qs.begin();
BIT<int> bit(N);
rep(i, N){
bit.add(ord[i], 1);
while(q != qs.end() && q->cen() == i){
(bit.range_sum(q->l, q->r) < q->x ? q->lb : q->ub) = q->cen();
++q;
}
}
sort(ALL(qs), [](auto a, auto b){ return a.cen() < b.cen(); });
//for(auto e : qs) cout<<e.id<<' '<<e.lb<<' '<<e.ub<<endl;
_n >>= 1;
}
sort(ALL(qs), [](auto a, auto b){ return a.id < b.id; });
for(auto q : qs) cout<<S[ord[q.ub]]<<endl;
}
carrot46