답안 #920389

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920389 2024-02-02T14:03:23 Z silv723 Autobahn (COI21_autobahn) C++17
50 / 100
660 ms 524288 KB
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll=long long;
using ld=long double;
using ull=unsigned long long;
using i128 = __int128_t;
#define vs vector<string>
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define rep2(i,n) for(ll i=n-1;i>=0;i--)
#define rep3(i,a,b) for(ll i=a;i<=ll(b);i++)
#define rep4(i,a,b) for(ll i=a;i>=ll(b);i--)
#define forv(i,V) for(const auto& i:V)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define SIZE(x) int(x.size())
constexpr ll mod=998244353;
//constexpr ll mod=1000000007;
#define pi 3.14159265358979323
#define INF32 2147483647
#define INF64 9223372036854775807
#define faster ios::sync_with_stdio(false);std::cin.tie(nullptr)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rev reverse
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define prq priority_queue
#define lb lower_bound
#define ub upper_bound
#define popcnt __builtin_popcountll
#define TLE while(true);
#define RE assert(false);
#define MLE vector<vector<vector<long long>>> mle_mle(400,vector<vector<long long>>(1000,vector<long long>(1000)));
const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
#define rall(n) (n).rbegin(),(n).rend()
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
template<typename T,typename U>
ostream &operator<<(ostream&os,const pair<T,U>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T,typename U>
istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<typename T>
ostream &operator<<(ostream&os,const vector<T>&v){for(auto it=v.begin();it!=v.end();){os<<*it<<((++it)!=v.end()?" ":"");}return os;}
template<typename T>
istream &operator>>(istream&is,vector<T>&v){for(T &in:v){is>>in;}return is;}
void scan(){}
template<class Head,class... Tail>
void scan(Head&head,Tail&... tail){cin>>head;scan(tail...);}
template<class T>
void print(const T &t){cout<<t<<'\n';}
template<class Head, class... Tail>
void print(const Head &head, const Tail &... tail){cout<<head<<' ';print(tail...);}
template<class... T>
void fin(const T &... a){print(a...);exit(0);}
ll max(int a,ll b){return max((ll)a,b);}
ll max(ll a,int b){return max((ll)b,a);}
ll min(int a,ll b){return min((ll)a,b);}
ll min(ll a,int b){return min((ll)b,a);}
//a以上b以下の個数
template<typename T>
ll RangeOK(ll a,ll b,vector<T> &v){
  return max(ub(all(v),b)-lb(all(v),a),0);
}
template <typename T>
vector<T> compress(vector<T> &X) {
    vector<T> vals = X;
    sort(vals.begin(), vals.end());
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    for (int i = 0; i < (int)X.size(); i++) {
        X[i] = lower_bound(vals.begin(), vals.end(), X[i]) - vals.begin();
    }
    return vals;
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
struct DinamicLazySegmentTreeUpdateSum{
  struct node{
    long long value;
    long long lazy;
    bool islz;
    node* left;
    node* right;
    node(long long value) : value(value), left(nullptr), right(nullptr) {
      islz = false;
    };
  };
  int n;
  node* root = new node(0);
  void mk(node*& t){
    if(!t) t = new node(0);
  }
  void eval(node*& t){
    if(t->islz == false) return;
    mk(t->left);
    t->left->lazy = t->lazy/2;
    t->left->islz = true;
    mk(t->right);
    t->right->lazy = t->lazy/2;
    t->right->islz = true;
    t->value = t->lazy;
    t->islz = false;
  }
  void update(node*& t, long long a, long long b, long long l, long long r, long long x){
    mk(t);
    eval(t);
    if(b <= l || r <= a) return;
    if(l <= a && b <= r){
      t->lazy = x*(b-a);
      t->islz = true;
      eval(t);
      return;
    }
    if(a-b != 1){
      long long c = (a+b)>>1;
      update(t->left, a, c, l, r, x);
      update(t->right, c, b, l, r, x);
    }
    t->value = t->left->value + t->right->value;
  }
  long long sum(node*& t, long long a, long long b, long long l, long long r){
    if(!t || b <= l || r <= a) return 0;
    eval(t);
    if(l <= a && b <= r) return t->value;
    long long c = (a+b)>>1;
    return sum(t->left, a, c, l, r) + sum(t->right, c, b, l, r);
  }
  //[a, b) -> x
  void update(long long a, long long b, long long x){
    update(root, -(1LL<<31), (1LL<<31), a, b, x);
  }
  //sum[a, b)
  long long sum(long long a, long long b){
    return sum(root, -(1LL<<31), (1LL<<31), a, b);
  }
};
int main(){
  INT(n, k, p);
  vvll v(n, vll(3));
  scan(v);
  vpll a, b;
  vll c;
  rep(i, n){
    a.pb({v[i][0], 1});
    a.pb({v[i][2]+1, -1});
    b.pb({min(v[i][0]+v[i][1], v[i][2]+1), 1});
    b.pb({v[i][2]+1, -1});
    c.pb(v[i][0]);
    c.pb(v[i][2]+1);
    c.pb(min(v[i][0]+v[i][1], v[i][2]+1));
    c.pb(v[i][2]+1);
  }
  sort(all(a));
  sort(all(b));
  sort(all(c));
  c.erase(unique(all(c)), c.end());
  DinamicLazySegmentTreeUpdateSum d1, d2;
  for(auto [x, y]:a){
    d1.update(x, (1LL<<30), d1.sum(x, x+1)+y);
  }
  for(auto [x, y]:b){
    d2.update(x, (1LL<<30), d2.sum(x, x+1)+y);
  }
  for(int i = 0; i+1 < c.size(); i++){
    if(d1.sum(c[i], c[i]+1) < k) d2.update(c[i], c[i+1], 0);
  }
  ll ans = 0;
  for(auto x:c){
    ans = max(ans, d2.sum(x, x+p));
    ans = max(ans, d2.sum(x+1, x+1+p));
    ans = max(ans, d2.sum(x-p, x));
    ans = max(ans, d2.sum(x-p-1, x-1));
  }
  fin(ans);
}

Compilation message

autobahn.cpp: In function 'int main()':
autobahn.cpp:181:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  181 |   for(int i = 0; i+1 < c.size(); i++){
      |                  ~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 4 ms 856 KB Output is correct
13 Correct 4 ms 856 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 4 ms 860 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 4 ms 860 KB Output is correct
18 Correct 5 ms 1328 KB Output is correct
19 Correct 4 ms 860 KB Output is correct
20 Correct 4 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 4 ms 856 KB Output is correct
13 Correct 4 ms 856 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 4 ms 860 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 4 ms 860 KB Output is correct
18 Correct 5 ms 1328 KB Output is correct
19 Correct 4 ms 860 KB Output is correct
20 Correct 4 ms 856 KB Output is correct
21 Runtime error 660 ms 524288 KB Execution killed with signal 9
22 Halted 0 ms 0 KB -