답안 #156053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
156053 2019-10-03T03:38:35 Z IOrtroiii 허수아비 (JOI14_scarecrows) C++14
0 / 100
479 ms 10796 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
   int n;
   scanf("%d", &n);
   vector<int> x(n);
   vector<int> y(n);
   {
      vector<pair<int, int>> ps;
      for (int i = 0; i < n; ++i) {
         int x, y;
         scanf("%d %d", &x, &y);
         ps.emplace_back(x, y);
      }
      sort(ps.begin(), ps.end());
      for (int i = 0; i < n; ++i) {
         x[i] = ps[i].first;
         y[i] = ps[i].second;
      }
   }
   ll ans = 0;
   function<void(int, int)> solve = [&](int l, int r) {
      if (l == r) {
         return;
      }
      int md = (l + r) >> 1;
      vector<tuple<int, int, int>> vals;
      for (int i = l; i <= md; ++i) {
         vals.emplace_back(y[i], x[i], -1);
      }
      for (int i = md + 1; i <= r; ++i) {
         vals.emplace_back(y[i], x[i], +1);
      }
      sort(vals.begin(), vals.end());
      vector<pair<int, int>> st1, st2;
      for (auto v : vals) {
         int y, x, tp;
         tie(y, x, tp) = v;
         if (tp == -1) {
            while (st1.size() && x > st1.back().second) {
               st1.pop_back();
            }
            st1.emplace_back(y, x);
         } else {
            int lim = 0;
            while (st2.size() && x > st2.back().second) {
               lim = max(lim, st2.back().first);
               st2.pop_back();
            }
            int fs = lower_bound(st1.begin(), st1.end(), make_pair(lim, 0)) - st1.begin();
            ans += (st1.size()) - fs;
            st2.emplace_back(y, x);
         }
      }
      solve(l, md);
      solve(md + 1, r);
   };
   solve(0, n - 1);
   printf("%lld\n", ans);
}

Compilation message

scarecrows.cpp: In function 'int main()':
scarecrows.cpp:9:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &n);
    ~~~~~^~~~~~~~~~
scarecrows.cpp:16:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
          scanf("%d %d", &x, &y);
          ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 632 KB Output is correct
2 Incorrect 11 ms 504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 279 ms 10796 KB Output is correct
2 Incorrect 479 ms 7976 KB Output isn't correct
3 Halted 0 ms 0 KB -