結果

問題 No.649 ここでちょっとQK!
ユーザー LightBellsLightBells
提出日時 2018-03-07 23:13:30
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,317 bytes
コンパイル時間 576 ms
コンパイル使用メモリ 57,432 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 05:42:49
合計ジャッジ時間 17,480 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 35 ms
6,944 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 3 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 RE -
testcase_31 RE -
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 1 ms
6,940 KB
testcase_35 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:102:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  102 |     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",&sw);
      |         ~~~~~^~~~~~~~~~
main.cpp:108:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  108 |             scanf("%lld",&temp);
      |             ~~~~~^~~~~~~~~~~~~~

ソースコード

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[20000];

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;
    scanf("%d %d",&q,&k);
    for (int i=0;i<q;i++){
        int sw;
        scanf("%d",&sw);
        if (sw==1){
            unsigned long long temp;
            scanf("%lld",&temp);
            sortedInsert(temp);
        }
        else if(sw==2){
            Node* temp = smaller_from(k-1);
            printf("%lld\n",temp->value);
            deleteNode(temp);
        }
    }
    cleanup();
    return 0;
}
0