제출 #1124230

#제출 시각아이디문제언어결과실행 시간메모리
1124230seoul_koreaCurtains (NOI23_curtains)C++17
100 / 100
1114 ms59832 KiB
#include <bits/stdc++.h> using namespace std; #define TASK "curtains" #define REP(i, n) for(int i = 1; i <= n; i++) #define FOR(i, a, b) for(auto i = a; i <= b; i++) #define FORD(i, a, b) for(auto i = a; i >= b; i--) template<class T> bool maximize(T& a, T b) { if(a < b) return a = b, 1; return 0; } template<class T> bool minimize(T& a, T b) { if(a > b) return a = b, 1; return 0; } const int N = (int)5e5 + 7; int n, m, q; vector<array<int, 2>> query[N]; vector<int> adj[N]; int node[N * 4][2]; bool ans[N]; void Down(int id) { if(node[id][1]) { maximize(node[id << 1][0], node[id][1]); maximize(node[id << 1][1], node[id][1]); maximize(node[id << 1 | 1][0], node[id][1]); maximize(node[id << 1 | 1][1], node[id][1]); node[id][1] = 0; } } void Upd(int id, int l, int r, int u, int v, int val) { if(u > r || v < l) return; if(u <= l && r <= v) { maximize(node[id][0], val); maximize(node[id][1], val); return; } Down(id); int m = l + r >> 1; Upd(id << 1, l, m, u, v, val); Upd(id << 1 | 1, m + 1, r, u, v, val); node[id][0] = min(node[id << 1][0], node[id << 1 | 1][0]); } void Upd(int l, int r, int val) { return Upd(1, 1, n, l, r, val); } int Get(int id, int l, int r, int u, int v) { if(u > r || v < l) return n + 1; if(u <= l && r <= v) return node[id][0]; Down(id); int m = l + r >> 1; return min(Get(id << 1, l, m, u, v), Get(id << 1 | 1, m + 1, r, u, v)); } int Get(int l, int r) { return Get(1, 1, n, l, r); } signed main() { cin.tie(0)->ios_base::sync_with_stdio(0); if(fopen("TASK.INP", "r")) freopen("TASK.INP", "r", stdin); if(fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } cin >> n >> m >> q; REP(i, m) { int u, v; cin >> u >> v; adj[v].push_back(u); } REP(i, q) { int l, r; cin >> l >> r; query[r].push_back({l, i}); } REP(i, n) { for(int l : adj[i]) Upd(l, i, l); for(array<int, 2> qu : query[i]) { int l = qu[0]; int id = qu[1]; if(Get(l, i) == l) ans[id] = 1; } } REP(i, q) cout << (ans[i] ? "YES" : "NO") << '\n'; return 0; }

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

curtains.cpp: In function 'int main()':
curtains.cpp:73:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |     if(fopen("TASK.INP", "r")) freopen("TASK.INP", "r", stdin);
      |                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
curtains.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
curtains.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...