제출 #1273693

#제출 시각아이디문제언어결과실행 시간메모리
1273693baotoan655운세 보기 2 (JOI14_fortune_telling2)C++20
100 / 100
181 ms31160 KiB
#include <bits/stdc++.h> #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } using namespace std; const int N = 2e5 + 5, L = 18; int n, q; pair<int, int> a[N]; bool rev[N]; int Q[N]; int bit[N]; int lst[N], sp[N][L]; int ord[N]; vector<int> ve[N]; int get_max(int l, int r) { if(l > r) return 0; int k = __lg(r - l + 1); return max(sp[l][k], sp[r - (1 << k) + 1][k]); } void upd(int i, int val) { for(++i; i < N; i += i & -i) bit[i] += val; } int get(int i) { int res = 0; for(++i; i > 0; i -= i & -i) res += bit[i]; return res; } int get(int l, int r) { if(l > r) return 0; return get(r) - get(l - 1); } int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); file("A") else file("task"); cin >> n >> q; for(int i = 1; i <= n; ++i) { cin >> a[i].first >> a[i].second; if(a[i].first < a[i].second) { swap(a[i].first, a[i].second); rev[i] = true; } ord[i] = i; } vector<int> zip; for(int i = 1; i <= q; ++i) { cin >> Q[i]; zip.emplace_back(Q[i]); } sort(zip.begin(), zip.end()); zip.resize(unique(zip.begin(), zip.end()) - zip.begin()); for(int i = 1; i <= q; ++i) { Q[i] = lower_bound(zip.begin(), zip.end(), Q[i]) - zip.begin() + 1; lst[Q[i]] = i; ve[Q[i]].emplace_back(i); } int m = zip.size(); for(int i = 1; i <= m; ++i) { sp[i][0] = lst[i]; } for(int j = 1; j < L; ++j) { for(int i = 1; i + (1 << j) - 1 <= m; ++i) { sp[i][j] = max(sp[i][j - 1], sp[i + (1 << j - 1)][j - 1]); } } long long ans = 0; sort(ord + 1, ord + n + 1, [&](int i, int j){ return a[i].first > a[j].first; }); int kk = m; for(int _ = 1; _ <= n; ++_) { int i = ord[_]; if(a[i].first == a[i].second) { ans += a[i].first; continue; } int mx = lower_bound(zip.begin(), zip.end(), a[i].first) - zip.begin() + 1; int mn = lower_bound(zip.begin(), zip.end(), a[i].second) - zip.begin() + 1; while(kk >= mx) { for(int x : ve[kk]) upd(x, 1); --kk; } int lst = get_max(mn, mx - 1); int t2 = get(lst + 1, q) % 2; if(rev[i] && lst == 0) t2 ^= 1; ans += (t2 ? a[i].second : a[i].first); // cout << ans << '\n'; } cout << ans << '\n'; return 0; }

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

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:2:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:36:5: note: in expansion of macro 'file'
   36 |     file("A") else file("task");
      |     ^~~~
fortune_telling2.cpp:2:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:36:5: note: in expansion of macro 'file'
   36 |     file("A") else file("task");
      |     ^~~~
fortune_telling2.cpp:2:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:36:20: note: in expansion of macro 'file'
   36 |     file("A") else file("task");
      |                    ^~~~
fortune_telling2.cpp:2:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:36:20: note: in expansion of macro 'file'
   36 |     file("A") else file("task");
      |                    ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...