結果
| 問題 |
No.59 鉄道の旅
|
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2022-12-20 02:50:28 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,368 bytes |
| コンパイル時間 | 1,216 ms |
| コンパイル使用メモリ | 144,612 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-18 01:44:00 |
| 合計ジャッジ時間 | 4,437 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 2 RE * 10 |
ソースコード
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
using namespace std;
//RSQ (0-indexed)
template<class T> struct BIT {
vector<T> bit;
long long N;
T P;
BIT (long long n, T p = 0){
N = n;
P = p;
bit.resize(N);
}
void add(long long loc, T val){
loc++;
while(loc <= N){
bit[loc-1] += val;
if (P) bit[loc-1] %= P;
loc += loc & -loc;
}
}
long long sum(long long l, long long r){
T res = _sum(r) - _sum(l-1);
if (P) res = (res + P) % P;
return res;
}
long long _sum(long long r){
r++;
T res = 0;
while(r > 0){
res += bit[r-1];
if (P) res %= P;
r -= r & -r;
}
return res;
}
};
int main(){
long long N, K, W, cnt;
cin >> N >> K;
BIT<long long> tree(100001);
for (int i=0; i<N; i++){
cin >> W;
if (W > 0){
cnt = tree.sum(W, 100000);
if (cnt < K) tree.add(W, 1);
}
else{
W *= -1;
if (tree.sum(W, W) > 0) tree.add(W, -1);
}
}
cout << tree.sum(0, 100000) << endl;
return 0;
}
srjywrdnprkt