Submission #222709

# Submission time Handle Problem Language Result Execution time Memory
222709 2020-04-13T21:02:14 Z Bruteforceman trapezoid (balkan11_trapezoid) C++11
100 / 100
372 ms 28920 KB
#include <bits/stdc++.h>
using namespace std;
const int mod = 30013;
struct trapz {
  int a, b, c, d;
} arr[100010];
int n;
int change[2 * 100010];

struct data {
  int val, cnt;
  data (int val, int cnt) : val(val), cnt(cnt) {}
  data ()  {} 
} t[8 * 100010], dp[100010];
data operator + (data p, data q) {
  if(p.val < q.val) return q;
  else if (p.val > q.val) return p;
  else return data(p.val, (p.cnt + q.cnt) % mod);
}

void update(int x, data d, int c = 1, int b = 1, int e = 2 * n) {
  if(b == e) {
    t[c] = d;
    return ;
  }
  int m = (b + e) >> 1;
  int l = c << 1;
  int r = l + 1;
  if(x <= m) update(x, d, l, b, m);
  else update(x, d, r, m + 1, e);
  t[c] = t[l] + t[r];
}
data query(int x, int y, int c = 1, int b = 1, int e = 2 * n) {
  if(x > y) return data(0, 0);
  if(x <= b && e <= y) return t[c];
  if(y < b || e < x) return data(0, 0);
  int m = (b + e) >> 1;
  int l = c << 1;
  int r = l + 1;
  return query(x, y, l, b, m) + query(x, y, r, m + 1, e);
}
int main() {
  scanf("%d", &n);
  map <int, int> cmpA, cmpB;
  for(int i = 1; i <= n; i++) {
    scanf("%d %d %d %d", &arr[i].a, &arr[i].b, &arr[i].c, &arr[i].d);
    cmpA[arr[i].a]; cmpA[arr[i].b];
    cmpB[arr[i].c]; cmpB[arr[i].d];
  }
  int idx = 0;
  for(auto &i : cmpA) i.second = ++idx;
  idx = 0;
  for(auto &i : cmpB) i.second = ++idx;
  for(int i = 1; i <= n; i++) {
    arr[i].a = cmpA[arr[i].a];
    arr[i].b = cmpA[arr[i].b];
    arr[i].c = cmpB[arr[i].c];
    arr[i].d = cmpB[arr[i].d];
  }
  for(int i = 1; i <= n; i++) {
    change[arr[i].a] = i;
    change[arr[i].b] = -i;
  }
  for(int i = 1; i <= 2 * n; i++) {
    int x = abs(change[i]);
    if(change[i] < 0) {
      update(arr[x].d, dp[x]);
    } else if (change[i] > 0) {
      dp[x] = query(1, arr[x].c - 1);
      dp[x].val += 1;
      if(dp[x].val == 1) dp[x].cnt = 1;
    }
  }
  data ans (0, 0);
  for(int i = 1; i <= n; i++) {
    ans = ans + dp[i];
  }
  printf("%d %d\n", ans.val, ans.cnt);
  return 0;
}

Compilation message

trapezoid.cpp: In function 'int main()':
trapezoid.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
trapezoid.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d", &arr[i].a, &arr[i].b, &arr[i].c, &arr[i].d);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 8 ms 896 KB Output is correct
6 Correct 11 ms 1152 KB Output is correct
7 Correct 13 ms 1408 KB Output is correct
8 Correct 17 ms 1792 KB Output is correct
9 Correct 29 ms 3328 KB Output is correct
10 Correct 56 ms 6264 KB Output is correct
11 Correct 76 ms 7416 KB Output is correct
12 Correct 166 ms 14712 KB Output is correct
13 Correct 207 ms 17140 KB Output is correct
14 Correct 247 ms 21624 KB Output is correct
15 Correct 303 ms 22904 KB Output is correct
16 Correct 337 ms 24056 KB Output is correct
17 Correct 330 ms 25376 KB Output is correct
18 Correct 281 ms 26564 KB Output is correct
19 Correct 323 ms 27232 KB Output is correct
20 Correct 372 ms 28920 KB Output is correct