Submission #144315

#TimeUsernameProblemLanguageResultExecution timeMemory
144315SamAndTenis (COI19_tenis)C++17
100 / 100
256 ms8176 KiB
#include <bits/stdc++.h> using namespace std; #define m_p make_pair const int N = 100005; struct ban { int laz; int i, minu; ban(){} ban(int i, int minu) { laz = 0; this->i = i; this->minu = minu; } }; int n, q; int a[N][4]; int maxu(int i) { int ans = 0; for (int k = 1; k <= 3; ++k) ans = max(ans, a[i][k]); return ans; } ban t[N * 4]; ban mer(const ban& l, const ban& r) { if (l.minu < r.minu) return l; if (l.minu > r.minu) return r; if (l.i < r.i) return l; return r; } void bil(int tl, int tr, int pos) { if (tl == tr) { t[pos] = ban(tl, tl); return; } int m = (tl + tr) / 2; bil(tl, m, pos * 2); bil(m + 1, tr, pos * 2 + 1); t[pos] = mer(t[pos * 2], t[pos * 2 + 1]); } void shi(int pos) { if (t[pos].laz == 0) return; t[pos * 2].minu += t[pos].laz; t[pos * 2 + 1].minu += t[pos].laz; t[pos * 2].laz += t[pos].laz; t[pos * 2 + 1].laz += t[pos].laz; t[pos].laz = 0; } void ubd(int tl, int tr, int l, int r, int y, int pos) { if (tl == l && tr == r) { t[pos].minu += y; t[pos].laz += y; return; } shi(pos); int m = (tl + tr) / 2; if (r <= m) ubd(tl, m, l, r, y, pos * 2); else if (l > m) ubd(m + 1, tr, l, r, y, pos * 2 + 1); else { ubd(tl, m, l, m, y, pos * 2); ubd(m + 1, tr, m + 1, r, y, pos * 2 + 1); } t[pos] = mer(t[pos * 2], t[pos * 2 + 1]); t[pos].laz = 0; } int main() { //freopen("input.txt", "r", stdin); scanf("%d%d", &n, &q); for (int k = 1; k <= 3; ++k) { for (int i = 1; i <= n; ++i) { int x; scanf("%d", &x); a[x][k] = i; } } bil(1, n, 1); for (int i = 1; i <= n; ++i) ubd(1, n, maxu(i), n, -1, 1); while (q--) { int ty; scanf("%d", &ty); if (ty == 1) { int x; scanf("%d", &x); if (maxu(x) <= t[1].i) printf("DA\n"); else printf("NE\n"); } else { int p, x, y; scanf("%d%d%d", &p, &x, &y); ubd(1, n, maxu(x), n, 1, 1); ubd(1, n, maxu(y), n, 1, 1); swap(a[x][p], a[y][p]); ubd(1, n, maxu(x), n, -1, 1); ubd(1, n, maxu(y), n, -1, 1); } } return 0; }

Compilation message (stderr)

tenis.cpp: In function 'int main()':
tenis.cpp:92:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~
tenis.cpp:98:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
tenis.cpp:108:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &ty);
         ~~~~~^~~~~~~~~~~
tenis.cpp:112:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
tenis.cpp:121:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d%d", &p, &x, &y);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...