結果
問題 |
No.649 ここでちょっとQK!
|
ユーザー |
![]() |
提出日時 | 2018-09-09 16:18:51 |
言語 | C90 (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 630 ms / 3,000 ms |
コード長 | 1,389 bytes |
コンパイル時間 | 441 ms |
コンパイル使用メモリ | 22,144 KB |
実行使用メモリ | 246,144 KB |
最終ジャッジ日時 | 2024-12-23 14:29:01 |
合計ジャッジ時間 | 9,128 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
コンパイルメッセージ
main.c: In function ‘run’: main.c:50:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 50 | scanf("%d%d",&q,&k); | ^~~~~~~~~~~~~~~~~~~ main.c:56:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 56 | scanf("%d",&c); | ^~~~~~~~~~~~~~ main.c:59:7: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 59 | scanf("%lld",&v); | ^~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h> #include<stdlib.h> typedef long long int int64; typedef struct segmentNode{ int v; struct segmentNode *left,*right; } segNode; segNode* newNode(void){ segNode *res=(segNode *)malloc(sizeof(segNode)); res->v=0; res->left=NULL; res->right=NULL; return res; } int eval(segNode *p){ return p==NULL?0:p->v; } segNode* update(segNode *p,int64 l,int64 r,const int64 index,const int v){ if(p==NULL) p=newNode(); if(l==index && r==index){ p->v+=v; return p; } int64 m=(l+r)/2; if(index<=m){ p->left=update(p->left,l,m,index,v); } else { p->right=update(p->right,m+1,r,index,v); } p->v=eval(p->left)+eval(p->right); return p; } int64 search(segNode *p,int64 l,int64 r,int k){ if(l==r){ return eval(p)>=k?l:-1; } if(eval(p)<k) return -1; int64 m=(l+r)/2; return eval(p->left)<k?search(p->right,m+1,r,k-eval(p->left)):search(p->left,l,m,k); } void run(void){ int q,k; scanf("%d%d",&q,&k); int64 l=0; int64 r=1000000000000000000LL; segNode *root=NULL; while(q--){ int c; scanf("%d",&c); if(c==1){ int64 v; scanf("%lld",&v); root=update(root,l,r,v,1); } else if(eval(root)<k){ printf("-1\n"); } else { int64 v=search(root,l,r,k); printf("%lld\n",v); root=update(root,l,r,v,-1); } } return; } int main(void){ run(); return 0; }