結果

問題 No.59 鉄道の旅
ユーザー LayCurseLayCurse
提出日時 2014-11-07 00:00:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 2,534 bytes
コンパイル時間 1,216 ms
コンパイル使用メモリ 146,120 KB
実行使用メモリ 7,528 KB
最終ジャッジ日時 2023-08-26 05:27:08
合計ジャッジ時間 2,142 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,476 KB
testcase_01 AC 4 ms
7,396 KB
testcase_02 AC 4 ms
7,424 KB
testcase_03 AC 4 ms
7,504 KB
testcase_04 AC 12 ms
7,260 KB
testcase_05 AC 3 ms
7,236 KB
testcase_06 AC 4 ms
7,256 KB
testcase_07 AC 4 ms
7,264 KB
testcase_08 AC 5 ms
7,264 KB
testcase_09 AC 5 ms
7,272 KB
testcase_10 AC 5 ms
7,308 KB
testcase_11 AC 4 ms
7,528 KB
testcase_12 AC 6 ms
7,248 KB
testcase_13 AC 10 ms
7,356 KB
testcase_14 AC 10 ms
7,240 KB
testcase_15 AC 3 ms
7,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

#define ll long long
#define ull unsigned ll

void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(int *x, int *y){reader(x);reader(y);}
void reader(int *x, int *y, int *z){reader(x);reader(y);reader(z);}
void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}

void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}

typedef struct struct_intfenwick{
  int size, memory;
  int *data;
}intFenwickTree;

intFenwickTree intFenwickTreeNew(int memory){
  intFenwickTree res;
  res.memory=memory; res.data=(int*)malloc(memory*sizeof(int));
  return res;
}

void intFenwickTreeDelete(intFenwickTree *t){free(t->data);}
void intFenwickTreeInit(intFenwickTree *t, int size){int i; t->size=size; rep(i,size) t->data[i]=0;}
void intFenwickTreeAdd(intFenwickTree *t,int k,int add){while(k<t->size)t->data[k]+=add, k|=k+1;}
int intFenwickTreeGet(intFenwickTree *t,int k){int res=0; while(k>=0)res+=t->data[k],k=(k&(k+1))-1; return res;}
int intFenwickTreeRange(intFenwickTree *t,int a,int b){return intFenwickTreeGet(t,b)-intFenwickTreeGet(t,a-1);}

int main(){
  int i, j, k;
  int N, K, W;
  intFenwickTree t = intFenwickTreeNew(1000100);
  
  intFenwickTreeInit(&t, 1000100);
  reader(&N,&K);
  while(N--){
    reader(&W);
    if(W>0){
      if(intFenwickTreeRange(&t,W,1000100) >= K) continue;
      intFenwickTreeAdd(&t,W,1);
    } else {
      W = -W;
      if(intFenwickTreeRange(&t,W,W)) intFenwickTreeAdd(&t,W,-1);
    }
  }
  writer(intFenwickTreeGet(&t,1000001),'\n');

  return 0;
}
0