답안 #1092508

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092508 2024-09-24T08:52:41 Z NguyenPhucThang 사다리꼴 (balkan11_trapezoid) C++17
100 / 100
123 ms 14588 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 "test"

using namespace std;
const int base = 31;
const ll mod = 30013;
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, (a.se + b.se) % mod};
   return (a.fi < b.fi ? b : a);
}


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);

   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;
   }

   sort(all(v));

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

   ll maxdp = 0, cntres = 0;
   forr(i, 1, n) maxdp = max(maxdp, dp[i]);
   forr(i, 1, n) if (dp[i] == maxdp) cntres = (cntres + cnt[i]) % mod;
   cout << maxdp << " " << cntres;
   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:87:4: note: in expansion of macro 'forf'
   87 |    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:93:4: note: in expansion of macro 'forf'
   93 |    forf(i, 0, v.size()){
      |    ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 3 ms 860 KB Output is correct
7 Correct 4 ms 1152 KB Output is correct
8 Correct 6 ms 1308 KB Output is correct
9 Correct 11 ms 1908 KB Output is correct
10 Correct 21 ms 3408 KB Output is correct
11 Correct 27 ms 3860 KB Output is correct
12 Correct 59 ms 7676 KB Output is correct
13 Correct 69 ms 9112 KB Output is correct
14 Correct 85 ms 10908 KB Output is correct
15 Correct 89 ms 11576 KB Output is correct
16 Correct 102 ms 12284 KB Output is correct
17 Correct 101 ms 13056 KB Output is correct
18 Correct 96 ms 13568 KB Output is correct
19 Correct 111 ms 12904 KB Output is correct
20 Correct 123 ms 14588 KB Output is correct