結果

問題 No.649 ここでちょっとQK!
ユーザー LightBellsLightBells
提出日時 2018-03-07 22:53:35
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,150 bytes
コンパイル時間 1,184 ms
コンパイル使用メモリ 158,700 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-15 05:09:05
合計ジャッジ時間 7,049 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

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

int counter;
Node *nil;

void init(){
    nil = (Node*)malloc(sizeof(Node));
    nil->value = -1;
    nil->next = nil;
    nil->prev = nil;
}

void customInsert(Node* base,unsigned long long ins){
    Node* add = (Node*)malloc(sizeof(Node));
    add-> value = ins;
    add-> next = base->next;
    add->prev = base;
    base->next->prev = add;
    base->next = add;
    counter++;
}

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

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

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

bool deleteFirst(){
    return deleteNode(nil->next);
}

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

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

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

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

void traceNode(){
    Node* cur= nil->next;
    while(cur!=nil){
        cout << cur->value << endl;
        cur = 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