제출 #144344

#제출 시각아이디문제언어결과실행 시간메모리
144344Minnakhmetov자리 배치 (IOI18_seats)C++14
37 / 100
4078 ms110840 KiB
#include "seats.h" #include<bits/stdc++.h> using namespace std; #pragma GCC opimize("Ofast") const int N = 1e6 + 5, INF = 1e9, G = 5; int n, m, len; vector<int> x, y; vector<vector<int>> num; int mn[N * 4], ct[N * 4], up[N * 4]; void push(int v, int L, int R) { if (up[v]) { if (L != R) { up[v * 2] += up[v]; up[v * 2 + 1] += up[v]; } mn[v] += up[v]; up[v] = 0; } } void upd(int l, int r, int x, int v, int L, int R) { push(v, L, R); if (l > r) return; if (l == L && r == R) { up[v] += x; push(v, L, R); } else { int m = (L + R) >> 1; upd(l, min(m, r), x, v * 2, L, m); upd(max(m + 1, l), r, x, v * 2 + 1, m + 1, R); mn[v] = mn[v * 2]; ct[v] = ct[v * 2]; if (mn[v * 2 + 1] < mn[v]) { mn[v] = mn[v * 2 + 1]; ct[v] = 0; } if (mn[v * 2 + 1] == mn[v]) { ct[v] += ct[v * 2 + 1]; } } } int anime[4]; void upd2times2(int a, int b, int d) { for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { anime[i + i + j] = num[a + i][b + j]; } } sort(anime, anime + 4); upd(anime[0], anime[1] - 1, d, 1, 0, len - 1); upd(anime[2], anime[3] - 1, d * G, 1, 0, len - 1); } void change(int a, int b, int d) { for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { upd2times2(a - i, b - j, d); } } } // void que(int v, int L, int R) { // push(v, L, R); // if (L == R) { // cout << t[v].mn << " "; // } // else { // int m = (L + R) >> 1; // que(v * 2, L, m); // que(v * 2 + 1, m + 1, R); // } // } void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { n = H; m = W; x = R; y = C; len = n * m; num.resize(n + 2, vector<int>(m + 2, len)); fill(ct, ct + len * 4, 1); for (int i = 0; i < len; i++) { x[i]++; y[i]++; num[x[i]][y[i]] = i; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { upd2times2(i, j, 1); } } } int swap_seats(int a, int b) { change(x[a], y[a], -1); num[x[a]][y[a]] = b; change(x[a], y[a], 1); change(x[b], y[b], -1); num[x[b]][y[b]] = a; change(x[b], y[b], 1); swap(x[a], x[b]); swap(y[a], y[b]); push(1, 0, len - 1); return mn[1] == 4 ? ct[1] : 0; }

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

seats.cpp:6:0: warning: ignoring #pragma GCC opimize [-Wunknown-pragmas]
 #pragma GCC opimize("Ofast")
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...