Submission #1092222

# Submission time Handle Problem Language Result Execution time Memory
1092222 2024-09-23T15:38:53 Z NguyenPhucThang trapezoid (balkan11_trapezoid) C++14
0 / 100
8 ms 8756 KB
#include <bits/stdc++.h>
#define forr(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define forf(i, a, b) for (int i = (a); i < (b); i++)
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(), v.end()
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "trapezoid"

using namespace std;
const int base = 31;
const ll mod = 1e9 + 7;
const ll oo = 1e18;
const int N = 1e6 + 5;

struct event{
   int x, y, type, idx;

   bool operator < (const event &other){
      if (x == other.x) return y < other.y;
      return x < other.x;
   }
};


pll st[4 * N];

pll combine(pll a, pll b){
   if (!a.fi && !b.fi) return {a.fi, 1};
   if (a.fi == b.fi) return {a.fi, a.se + b.se};
   return (a.fi < b.fi ? b : a);
}

void build(int id, int l, int r){
   st[id] = {0, 1};
   if (l == r) return;
   int mid = (l + r) >> 1;
   build(2 * id, l, mid), build(2 * id + 1, mid + 1, r);
   st[id] = combine(st[2 * id], st[2 * id + 1]);
}


void update(int id, int l, int r, int i, pll v){
   if (i < l || r < i) return;
   if (l == r){
      st[id] = combine(st[id], v);
      return;
   }

   int mid = (l + r) >> 1;
   update(2 * id, l, mid, i, v), update(2 * id + 1, mid + 1, r, i, v);
   st[id] = combine(st[2 * id], st[2 * id + 1]);
}

pll get(int id, int l, int r, int u, int v){
   if (v < l || r < u) return {0, 1};
   if (u <= l && r <= v) return st[id];
   int mid = (l + r) >> 1;
   return combine(get(2 * id, l, mid, u, v), get(2 * id + 1, mid + 1, r, u, v));
}

ll dp[N], cnt[N];

int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);

   freopen(file".in", "r", stdin);
   freopen(file".out", "w", stdout);


   int n;
   cin >> n;
   vector<event> v;
   vector<int> nen;
   forr(i, 1, n) {
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      if (a > b) swap(a, b);
      if (c > d) swap(c, d);  
      v.pb({a, c, 0, i});
      v.pb({b, d, 1, i});  
      nen.pb(c);
      nen.pb(d);
   }

   sort(all(nen));
   nen.resize(unique(all(nen)) - nen.begin());
   forf(i, 0, v.size()) {
      v[i].y = lower_bound(all(nen), v[i].y) - nen.begin() + 1;
   }

   forr(i, 1, n) cnt[i] = 1;
   build(1, 1, 2e5);

   sort(all(v));

   forf(i, 0, v.size()){
      if (v[i].type == 0){
         pll ans = get(1, 1, 2e5, 1, v[i].y - 1);
         int id = v[i].idx;
         dp[id] = ans.fi + 1;
         cnt[id] = ans.se;
      }
      else {
         int id = v[i].idx;
         update(1, 1, 2e5, v[i].y, {dp[id], cnt[id]});
      }
   }  


   int res_dp = 0, res_cnt;
   forr(i, 1, n) if (res_dp < dp[i]) res_dp = dp[i], res_cnt = cnt[i];
   cout << res_dp << " " << res_cnt;

   return 0;
}   

Compilation message

trapezoid.cpp: In function 'int main()':
trapezoid.cpp:4:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forf(i, a, b) for (int i = (a); i < (b); i++)
      |                                           ^
trapezoid.cpp:100:4: note: in expansion of macro 'forf'
  100 |    forf(i, 0, v.size()) {
      |    ^~~~
trapezoid.cpp:4:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forf(i, a, b) for (int i = (a); i < (b); i++)
      |                                           ^
trapezoid.cpp:109:4: note: in expansion of macro 'forf'
  109 |    forf(i, 0, v.size()){
      |    ^~~~
trapezoid.cpp:79:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |    freopen(file".in", "r", stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
trapezoid.cpp:80:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |    freopen(file".out", "w", stdout);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
trapezoid.cpp:125:29: warning: 'res_cnt' may be used uninitialized in this function [-Wmaybe-uninitialized]
  125 |    cout << res_dp << " " << res_cnt;
      |                             ^~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 8540 KB Unexpected end of file - int32 expected
2 Incorrect 7 ms 8540 KB Unexpected end of file - int32 expected
3 Incorrect 5 ms 8628 KB Unexpected end of file - int32 expected
4 Incorrect 5 ms 8540 KB Unexpected end of file - int32 expected
5 Incorrect 8 ms 8536 KB Unexpected end of file - int32 expected
6 Incorrect 5 ms 8540 KB Unexpected end of file - int32 expected
7 Incorrect 5 ms 8540 KB Unexpected end of file - int32 expected
8 Incorrect 8 ms 8540 KB Unexpected end of file - int32 expected
9 Incorrect 5 ms 8536 KB Unexpected end of file - int32 expected
10 Incorrect 6 ms 8540 KB Unexpected end of file - int32 expected
11 Incorrect 5 ms 8540 KB Unexpected end of file - int32 expected
12 Incorrect 5 ms 8540 KB Unexpected end of file - int32 expected
13 Incorrect 4 ms 8540 KB Unexpected end of file - int32 expected
14 Incorrect 7 ms 8540 KB Unexpected end of file - int32 expected
15 Incorrect 5 ms 8540 KB Unexpected end of file - int32 expected
16 Incorrect 5 ms 8540 KB Unexpected end of file - int32 expected
17 Incorrect 7 ms 8540 KB Unexpected end of file - int32 expected
18 Incorrect 5 ms 8540 KB Unexpected end of file - int32 expected
19 Incorrect 5 ms 8540 KB Unexpected end of file - int32 expected
20 Incorrect 5 ms 8756 KB Unexpected end of file - int32 expected