結果

問題 No.649 ここでちょっとQK!
ユーザー LightBells
提出日時 2018-03-08 21:21:50
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 2,383 bytes
コンパイル時間 493 ms
コンパイル使用メモリ 56,264 KB
実行使用メモリ 12,580 KB
最終ジャッジ日時 2024-10-05 08:15:36
合計ジャッジ時間 6,595 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other AC * 3 WA * 1 TLE * 1 -- * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:107:23: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘int*’ [-Wformat=]
  107 |             scanf("%lld",&qs[i][1]);
      |                    ~~~^  ~~~~~~~~~
      |                       |  |
      |                       |  int*
      |                       long long int*
      |                    %d
main.cpp:103:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  103 |     scanf("%d %d",&q,&k);
      |     ~~~~~^~~~~~~~~~~~~~~
main.cpp:105:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  105 |         scanf("%d",&qs[i][0]);
      |         ~~~~~^~~~~~~~~~~~~~~~
main.cpp:107:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  107 |             scanf("%lld",&qs[i][1]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <iostream>
using namespace std;

struct Node{
    unsigned long long value;
    int prev,next;
};

int memory_cursor;
int counter;
Node *nil;
Node list[200000];

void init(){
    nil = &list[0];
    nil->value = -1;
    nil->next = 0;
    nil->prev = 0;
    memory_cursor++;
}

void customInsert(int base,unsigned long long ins){
    Node* add = &list[memory_cursor];
    add-> value = ins;
    add-> next = list[base].next;
    add->prev = base;
    list[list[base].next].prev = memory_cursor;
    list[base].next = memory_cursor;
    memory_cursor++;
    counter++;
}

void insert(int ins){
    customInsert(0,ins);
}

void sortedInsert(unsigned long long key){
    Node* cur = &list[nil->next];
    while(key < cur->value && cur!=nil)
        cur = &list[cur->next];
    customInsert(cur->prev,key);
}

bool deleteNode(Node* del){
    if (del==nil) return false;
    list[del->next].prev = del->prev;
    list[del->prev].next = del->next;
    counter--;
    return true;
}

bool deleteFirst(){
    return deleteNode(&list[nil->next]);
}

void cleanup(){
    while(deleteFirst());
}

Node* searchNode(unsigned long long key){
    Node* cur = &list[nil->next];
    while(cur!=nil && cur->value!=key){
        cur = &list[cur->next];
    }
    return cur;
}

Node* bigger_from(int index){
    if (index>=counter) return nil;
    int count=1;
    Node* cur = &list[nil->next];
    while(count<index){
        cur = &list[cur->next];
        count++;
    }
    return cur;
}

Node* smaller_from(int index){
    if (index>=counter) return nil;
    int count=0;
    Node* cur = &list[nil->prev];
    while(count<index){
        cur = &list[cur->prev];
        count++;
    }
    return cur;
}

void traceNode(){
    Node* cur= &list[nil->next];
    while(cur!=nil){
        cout << cur->value << endl;
        cur = &list[cur->next];
    }
}

signed main(){
    init();
    int q,k;
    int qs[200000][2];
    scanf("%d %d",&q,&k);
    for (int i=0;i<q;i++){
        scanf("%d",&qs[i][0]);
        if (qs[i][0]==1){
            scanf("%lld",&qs[i][1]);
        }
    }
    for (int i=0;i<q;i++){
        if (qs[i][0]==1){
            sortedInsert(qs[i][1]);
        }
        else if(qs[i][0]==2){
            Node* temp = smaller_from(k-1);
            printf("%lld\n",temp->value);
            deleteNode(temp);
        }
    }
    cleanup();
    return 0;
}
0