結果
問題 | No.59 鉄道の旅 |
ユーザー | yaoshimax |
提出日時 | 2015-02-22 20:11:22 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 47 ms / 5,000 ms |
コード長 | 1,268 bytes |
コンパイル時間 | 654 ms |
コンパイル使用メモリ | 87,696 KB |
実行使用メモリ | 81,664 KB |
最終ジャッジ日時 | 2023-08-26 05:35:51 |
合計ジャッジ時間 | 1,780 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
81,096 KB |
testcase_01 | AC | 24 ms
81,168 KB |
testcase_02 | AC | 24 ms
81,092 KB |
testcase_03 | AC | 23 ms
81,168 KB |
testcase_04 | AC | 47 ms
81,296 KB |
testcase_05 | AC | 24 ms
81,096 KB |
testcase_06 | AC | 22 ms
81,040 KB |
testcase_07 | AC | 23 ms
81,084 KB |
testcase_08 | AC | 25 ms
81,164 KB |
testcase_09 | AC | 25 ms
81,168 KB |
testcase_10 | AC | 27 ms
81,160 KB |
testcase_11 | AC | 26 ms
81,144 KB |
testcase_12 | AC | 32 ms
81,104 KB |
testcase_13 | AC | 42 ms
81,180 KB |
testcase_14 | AC | 40 ms
81,048 KB |
testcase_15 | AC | 24 ms
81,664 KB |
ソースコード
#include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <complex> #include <stack> #include <queue> #include <cstring> using namespace std; class BIT{ /*binary indexed tree*/ private: vector<long long> data; int size; public: BIT(int n): data(n+1,0),size(n){ return; } long long sum(int l, int r ){ // return sum in [l+1,r] or (l,r] return sum_(r)-sum_(l); } long long sum_(int i){ // return sum (0, i] long long ans = 0; while( 0 < i ){ ans += data[i]; i -= i&-i; // 11010110 -> 1010100 } return ans; } void add(int i, int x){ // add x to i while( i <= size ){ data[i] += x; i+= i&-i; } return; } }; int main(){ int N,K; scanf("%d%d",&N,&K); BIT b(10000001); for( int i = 0 ; i < N; i++ ){ int w; scanf("%d",&w); if(w>0 && b.sum(w-1,1000000) < K){ b.add(w,1); } if(w<0 && b.sum(-w-1,-w) >0){ b.add(-w,-1); } } printf("%d\n",(int)b.sum_(1000000)); return 0; }