結果
| 問題 |
No.2803 Bocching Star
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-12 22:01:51 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 352 ms / 2,000 ms |
| コード長 | 1,856 bytes |
| コンパイル時間 | 3,475 ms |
| コンパイル使用メモリ | 258,324 KB |
| 実行使用メモリ | 21,112 KB |
| 最終ジャッジ日時 | 2024-07-12 22:02:04 |
| 合計ジャッジ時間 | 12,087 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, const T& b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, const T& b) {if (b<a) {a=b; return true;} return false;}
const int INTINF = 1000001000;
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const ll LLINF = 1000000000000000000;
#include "atcoder/lazysegtree.hpp"
using S_t = int;
using F_t = int;
S_t op (S_t a, S_t b) {
return a+b;
}
S_t e() {
return 0;
}
S_t mapping(F_t f, S_t x) {
return x + f;
}
F_t composition(F_t f, F_t g) {
return g + f;
}
F_t id(){
return 0;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N, S; cin >> N >> S;
vector<int>P(N); for(int i=0; i<N ; i++) cin >> P[i];
vector<int> cord;
for(int i=0; i<N; i++) {
cord.push_back(P[i]-S);
cord.push_back(P[i]+S+1);
cord.push_back(P[i]);
}
sort(cord.begin(), cord.end());
cord.erase(unique(cord.begin(), cord.end()), cord.end());
atcoder::lazy_segtree<S_t,op,e,F_t,mapping,composition,id> seg(cord.size());
for(int i=0; i<N; i++) {
// |P_i - P_J| <= S
// -S <= P_i - P_j <= S
// P_i - S <= P_j <= P_i + S
int idx = lower_bound(cord.begin(), cord.end(), P[i]) - cord.begin();
assert(binary_search(cord.begin(), cord.end(), P[i]));
seg.apply(idx, idx+1, 1);
}
vector<int>ans;
for(int i=0; i<N; i++) {
int l_idx = lower_bound(cord.begin(), cord.end(), P[i]-S) - cord.begin();
int r_idx = lower_bound(cord.begin(), cord.end(), P[i]+S+1) - cord.begin();
int sum = seg.prod(l_idx, r_idx);
if (sum == 1 ) {
ans.push_back(i+1);
}
}
cout << ans.size() << endl;
for(int i=0; i<int(ans.size()); i++) {
cout << ans[i] << " \n"[i == int(ans.size())-1];
}
return 0;
}