답안 #484051

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
484051 2021-11-02T02:32:43 Z Killer2501 Global Warming (CEOI18_glo) C++14
100 / 100
123 ms 22736 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<ll, pll>
#define fi first
#define se second
using namespace std;
const int N = 2e5+15;
const int M = 550;
const ll mod = 998244353;
const ld base = 1e6;
const ll inf = 1e16;
const ld pi = acos(-1);
ll n, m, k, ans,  cnt[N], t, h[N], c[N], tong, lab[N], a[N], b[N];
vector<ll> adj[N];
string s[N];
mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
vector<ll> kq;
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n&1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}
ll findp(ll u)
{
    return lab[u] < 0 ? u : lab[u] = findp(lab[u]);
}
void hop(ll u, ll v)
{
    if(lab[u] > lab[v])swap(u, v);
    lab[u] += lab[v];
    lab[v] = u;
    k = max(k, -lab[u]);
}
struct BIT
{
    ll n;
    vector<ll> fe;
    BIT(ll _n)
    {
        n = _n;
        fe.resize(n+1, 0);
    }
    void add(ll id, ll x)
    {
        for(; id <= n; id += id & -id)fe[id] = max(fe[id], x);
    }
    ll get(ll id)
    {
        ll total = 0;
        for(; id; id -= id & -id)total = max(total, fe[id]);
        return total;
    }
};

void sol()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        kq.pb(a[i]);
    }
    ans = 0;
    sort(kq.begin(), kq.end());
    kq.erase(unique(kq.begin(), kq.end()), kq.end());
    BIT l(n), r(n);
    for(int i = 1; i <= n; i ++)
    {
        b[i] = lower_bound(kq.begin(), kq.end(), a[i]+k) - kq.begin() + 1;
        a[i] = lower_bound(kq.begin(), kq.end(), a[i]) - kq.begin() + 1;
        c[i] = l.get(a[i]-1);
        m = max(l.get(b[i]-1), r.get(a[i]-1));
        l.add(a[i], c[i]+1);
        r.add(a[i], m+1);
    }
    cout << r.get(n);
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    #define task "tests"
    if(fopen(task".inp", "r"))
	{
		freopen(task".inp", "r", stdin);
		freopen(task".out", "w", stdout);
	}
    int test = 1;
    //cin >> test;
    while(test -- > 0)sol();
    return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:95:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:96:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11212 KB Output is correct
2 Correct 5 ms 11212 KB Output is correct
3 Correct 5 ms 11212 KB Output is correct
4 Correct 5 ms 11212 KB Output is correct
5 Correct 6 ms 11340 KB Output is correct
6 Correct 5 ms 11212 KB Output is correct
7 Correct 5 ms 11212 KB Output is correct
8 Correct 5 ms 11276 KB Output is correct
9 Correct 5 ms 11212 KB Output is correct
10 Correct 5 ms 11212 KB Output is correct
11 Correct 5 ms 11212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11212 KB Output is correct
2 Correct 5 ms 11212 KB Output is correct
3 Correct 5 ms 11212 KB Output is correct
4 Correct 5 ms 11212 KB Output is correct
5 Correct 6 ms 11340 KB Output is correct
6 Correct 5 ms 11212 KB Output is correct
7 Correct 5 ms 11212 KB Output is correct
8 Correct 5 ms 11276 KB Output is correct
9 Correct 5 ms 11212 KB Output is correct
10 Correct 5 ms 11212 KB Output is correct
11 Correct 5 ms 11212 KB Output is correct
12 Correct 5 ms 11288 KB Output is correct
13 Correct 5 ms 11212 KB Output is correct
14 Correct 5 ms 11212 KB Output is correct
15 Correct 5 ms 11212 KB Output is correct
16 Correct 5 ms 11212 KB Output is correct
17 Correct 5 ms 11212 KB Output is correct
18 Correct 5 ms 11212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11212 KB Output is correct
2 Correct 5 ms 11212 KB Output is correct
3 Correct 5 ms 11212 KB Output is correct
4 Correct 5 ms 11212 KB Output is correct
5 Correct 6 ms 11340 KB Output is correct
6 Correct 5 ms 11212 KB Output is correct
7 Correct 5 ms 11212 KB Output is correct
8 Correct 5 ms 11276 KB Output is correct
9 Correct 5 ms 11212 KB Output is correct
10 Correct 5 ms 11212 KB Output is correct
11 Correct 5 ms 11212 KB Output is correct
12 Correct 5 ms 11288 KB Output is correct
13 Correct 5 ms 11212 KB Output is correct
14 Correct 5 ms 11212 KB Output is correct
15 Correct 5 ms 11212 KB Output is correct
16 Correct 5 ms 11212 KB Output is correct
17 Correct 5 ms 11212 KB Output is correct
18 Correct 5 ms 11212 KB Output is correct
19 Correct 5 ms 11340 KB Output is correct
20 Correct 5 ms 11340 KB Output is correct
21 Correct 5 ms 11296 KB Output is correct
22 Correct 7 ms 11340 KB Output is correct
23 Correct 6 ms 11292 KB Output is correct
24 Correct 6 ms 11340 KB Output is correct
25 Correct 5 ms 11300 KB Output is correct
26 Correct 6 ms 11288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 22616 KB Output is correct
2 Correct 123 ms 22712 KB Output is correct
3 Correct 104 ms 22732 KB Output is correct
4 Correct 111 ms 22636 KB Output is correct
5 Correct 57 ms 21944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 14212 KB Output is correct
2 Correct 29 ms 14148 KB Output is correct
3 Correct 28 ms 14248 KB Output is correct
4 Correct 18 ms 14060 KB Output is correct
5 Correct 5 ms 11288 KB Output is correct
6 Correct 17 ms 14028 KB Output is correct
7 Correct 24 ms 14244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 17028 KB Output is correct
2 Correct 46 ms 17084 KB Output is correct
3 Correct 94 ms 22636 KB Output is correct
4 Correct 54 ms 21856 KB Output is correct
5 Correct 28 ms 16580 KB Output is correct
6 Correct 48 ms 21432 KB Output is correct
7 Correct 53 ms 22140 KB Output is correct
8 Correct 39 ms 17088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11212 KB Output is correct
2 Correct 5 ms 11212 KB Output is correct
3 Correct 5 ms 11212 KB Output is correct
4 Correct 5 ms 11212 KB Output is correct
5 Correct 6 ms 11340 KB Output is correct
6 Correct 5 ms 11212 KB Output is correct
7 Correct 5 ms 11212 KB Output is correct
8 Correct 5 ms 11276 KB Output is correct
9 Correct 5 ms 11212 KB Output is correct
10 Correct 5 ms 11212 KB Output is correct
11 Correct 5 ms 11212 KB Output is correct
12 Correct 5 ms 11288 KB Output is correct
13 Correct 5 ms 11212 KB Output is correct
14 Correct 5 ms 11212 KB Output is correct
15 Correct 5 ms 11212 KB Output is correct
16 Correct 5 ms 11212 KB Output is correct
17 Correct 5 ms 11212 KB Output is correct
18 Correct 5 ms 11212 KB Output is correct
19 Correct 5 ms 11340 KB Output is correct
20 Correct 5 ms 11340 KB Output is correct
21 Correct 5 ms 11296 KB Output is correct
22 Correct 7 ms 11340 KB Output is correct
23 Correct 6 ms 11292 KB Output is correct
24 Correct 6 ms 11340 KB Output is correct
25 Correct 5 ms 11300 KB Output is correct
26 Correct 6 ms 11288 KB Output is correct
27 Correct 106 ms 22616 KB Output is correct
28 Correct 123 ms 22712 KB Output is correct
29 Correct 104 ms 22732 KB Output is correct
30 Correct 111 ms 22636 KB Output is correct
31 Correct 57 ms 21944 KB Output is correct
32 Correct 27 ms 14212 KB Output is correct
33 Correct 29 ms 14148 KB Output is correct
34 Correct 28 ms 14248 KB Output is correct
35 Correct 18 ms 14060 KB Output is correct
36 Correct 5 ms 11288 KB Output is correct
37 Correct 17 ms 14028 KB Output is correct
38 Correct 24 ms 14244 KB Output is correct
39 Correct 45 ms 17028 KB Output is correct
40 Correct 46 ms 17084 KB Output is correct
41 Correct 94 ms 22636 KB Output is correct
42 Correct 54 ms 21856 KB Output is correct
43 Correct 28 ms 16580 KB Output is correct
44 Correct 48 ms 21432 KB Output is correct
45 Correct 53 ms 22140 KB Output is correct
46 Correct 39 ms 17088 KB Output is correct
47 Correct 55 ms 16992 KB Output is correct
48 Correct 53 ms 17052 KB Output is correct
49 Correct 108 ms 22720 KB Output is correct
50 Correct 57 ms 21944 KB Output is correct
51 Correct 48 ms 19264 KB Output is correct
52 Correct 68 ms 21992 KB Output is correct
53 Correct 50 ms 21984 KB Output is correct
54 Correct 60 ms 22736 KB Output is correct
55 Correct 89 ms 22680 KB Output is correct