제출 #38057

#제출 시각아이디문제언어결과실행 시간메모리
3805714kg입자 가속기 (IZhO11_collider)C++11
0 / 100
26 ms13812 KiB
#include <stdio.h> #define N 1000005 struct DB { char data; int left, right; } in[N]; int n, nn, hash[1001]; char temp[N]; int search(int x) { int w = hash[x / 1000], k = (x / 1000) * 1000; while (k < x) k++, w = in[w].right; return w; } int main() { int m, x, y; char s; scanf("%d %d %s ", &n, &m, temp + 1), nn = n / 1000; for (int i = 1; i <= nn; i++) hash[i] = i * 1000; in[0].right = 1; for (int i = 1; i <= n; i++) { in[i].data = temp[i], in[i].left = i - 1, in[i].right = i + 1; } while (m--) { scanf("%c ", &s); if (s == 'q') { scanf("%d ", &x); printf("%c\n", in[search(x)].data); } else { scanf("%d %d ", &x, &y); int wx = search(x), wy = search(y); if (x < y) { for (int i = (x - 1) / 1000 + 1; i <= y / 1000; i++) if (i == y / 1000) hash[i] = wx; else hash[i] = in[hash[i]].right; in[in[wx].left].right = in[wx].right; in[in[wx].right].left = in[wx].left; in[in[wy].right].left = wx; in[wx].left = wy; in[wx].right = in[wy].right; in[wy].right = wx; } if (y < x) { for (int i = (y - 1) / 1000 + 1; i <= x / 1000; i++) if (i == y / 1000) hash[i] = wx; else hash[i] = in[hash[i]].left; in[in[wx].left].right = in[wx].right; in[in[wx].right].left = in[wx].left; in[in[wy].left].right = wx; in[wx].left = in[wy].left; in[wx].right = wy; in[wy].left = wx; } } } }

컴파일 시 표준 에러 (stderr) 메시지

collider.cpp: In function 'int main()':
collider.cpp:21:53: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %s ", &n, &m, temp + 1), nn = n / 1000;
                                                     ^
collider.cpp:30:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%c ", &s);
                   ^
collider.cpp:32:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d ", &x);
                    ^
collider.cpp:36:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d ", &x, &y);
                           ^
#Verdict Execution timeMemoryGrader output
Fetching results...