Submission #737001

#TimeUsernameProblemLanguageResultExecution timeMemory
737001nguyentunglamAdvertisement 2 (JOI23_ho_t2)C++17
100 / 100
223 ms14820 KiB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 5e5 + 10;
int x[N], e[N], n;
vector<pair<int, int> > v;
struct BIT {
    int bit[N];
    void up(int pos, int val) {
        while (pos <= n) {
            bit[pos] = max(bit[pos], val);
            pos += pos & -pos;
        }
    }
    int get(int pos) {
        int ret = -2e9;
        while (pos) {
            ret = max(ret, bit[pos]);
            pos -= pos & -pos;
        }
        return ret;
    }
} bit[2];
int main() {
    #define task ""
    cin.tie(0) -> sync_with_stdio(0);
    if (fopen ("task.inp", "r")) {
        freopen ("task.inp", "r", stdin);
        freopen ("task.out", "w", stdout);
    }
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    cin >> n;
    for(int i = 1; i <= n; i++) {
        int x, y; cin >> x >> y;
        v.emplace_back(x, y);
        bit[0].bit[i] = bit[1].bit[i] = -2e9;
    }
    sort(v.begin(), v.end());
    for(int i = 1; i <= n; i++) tie(x[i], e[i]) = v[i - 1];

    v.clear();
    for(int i = 1; i <= n; i++) v.emplace_back(e[i], i);
    sort(v.begin(), v.end());
    int res = 0;
    while (!v.empty()) {
        int i = v.back().second; v.pop_back();
        if (bit[0].get(i) >= x[i] + e[i] || bit[1].get(n - i + 1) >= e[i] - x[i]) continue;
        res++;
        bit[0].up(i, x[i] + e[i]);
        bit[1].up(n - i + 1, e[i] - x[i]);
    }
    cout << res;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:31:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:32:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:35:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:36:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...