Submission #660564

# Submission time Handle Problem Language Result Execution time Memory
660564 2022-11-22T10:00:36 Z 600Mihnea trapezoid (balkan11_trapezoid) C++17
100 / 100
133 ms 13024 KB
bool home = 0;

#include <bits/stdc++.h>

using namespace std;

const int MODULO = 30013;

struct T
{
  int a;
  int b;
  int c;
  int d;
};

bool operator < (T first, T second)
{
  return first.a < second.a;
}

struct P
{
  int dp;
  int cnt;
};

P operator + (P a, P b)
{
  if (a.dp > b.dp)
  {
    return a;
  }
  if (a.dp < b.dp)
  {
    return b;
  }
  return {a.dp, (a.cnt + b.cnt) % MODULO};
}

int main()
{
  if (home == 0)
  {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  }
  else
  {
    freopen ("input.txt", "r", stdin);
  }

  int n;
  cin >> n;
  vector<T> v(n);
  map<int, int> mp;

  for (auto &it : v)
  {
    cin >> it.a >> it.b >> it.c >> it.d;
    it.c--;
    mp[it.c] = 0;
    mp[it.d] = 0;
  }
  int yahor = 0;
  for (auto &it : mp)
  {
    it.second = ++yahor;
  }
  for (auto &it : v)
  {
    it.c = mp[it.c];
    it.d = mp[it.d];
  }
  sort(v.begin(), v.end());
  vector<P> fw(yahor + 1);
  vector<int> iB(n);
  iota(iB.begin(), iB.end(), 0);
  sort(iB.begin(), iB.end(), [&] (int i, int j) {
    return v[i].b < v[j].b;
  });
  int ptr = 0;
  vector<int> dp(n, 0), ways(n, 0);
  for (int i = 0; i < n; i++)
  {
    while (ptr < n && v[iB[ptr]].b < v[i].a)
    {
      for (int x = v[iB[ptr]].d; x <= yahor; x += x & (-x))
      {
        fw[x] = fw[x] + P{dp[iB[ptr]] + 1, ways[iB[ptr]]};
      }
      ptr++;
    }
    P sol = {1, 1};
    for (int x = v[i].c; x; x -= x & (-x))
    {
      sol = sol + fw[x];
    }
    dp[i] = sol.dp;
    ways[i] = sol.cnt;
  }
  int mx = *max_element(dp.begin(), dp.end()), cnt = 0;
  for (int i = 0; i < n; i++)
  {
    if (dp[i] == mx)
    {
      cnt = (cnt + ways[i]) % MODULO;
    }
  }
  cout << mx << " " << cnt << "\n";
  return 0;
}

Compilation message

trapezoid.cpp: In function 'int main()':
trapezoid.cpp:49:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     freopen ("input.txt", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 4 ms 844 KB Output is correct
8 Correct 5 ms 784 KB Output is correct
9 Correct 11 ms 1404 KB Output is correct
10 Correct 21 ms 2900 KB Output is correct
11 Correct 26 ms 3620 KB Output is correct
12 Correct 61 ms 6752 KB Output is correct
13 Correct 73 ms 8128 KB Output is correct
14 Correct 95 ms 9808 KB Output is correct
15 Correct 98 ms 9396 KB Output is correct
16 Correct 110 ms 10340 KB Output is correct
17 Correct 112 ms 11320 KB Output is correct
18 Correct 108 ms 11488 KB Output is correct
19 Correct 120 ms 12844 KB Output is correct
20 Correct 133 ms 13024 KB Output is correct