Submission #970490

# Submission time Handle Problem Language Result Execution time Memory
970490 2024-04-26T15:49:45 Z hariaakas646 Snowball (JOI21_ho_t2) C++14
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;


void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}


int main() {
    usaco();
    int n, q;
    scd(n);
    scd(q);

    vll pos(n+2);
    pos[0] = -2e18;
    pos[n+1] = 2e18;
    frange(i, n) sclld(pos[i+1]);

    vll vec(q);

    frange(i, q) sclld(vec[i]);

    map<lli, int> po, ne;
    po[0] = -1;
    ne[0] = -1;

    lli tot = 0;
    frange(i, q) {
        tot += vec[i];
        if(tot >= 0) po[tot] = i;
        else ne[abs(tot)] = i;
    }

    int mi = 1e9;
    auto it = po.end();

    while(it != po.begin()) {
        it--;
        lli v = (*it).f;
        mi = min(mi, (*it).s);
        po[v] = mi;
        it = po.find(v);
    }
    it = ne.end();
    mi = 1e9;
    while(it != ne.begin()) {
        it--;
        lli v = (*it).f;
        mi = min(mi, (*it).s);
        ne[v] = mi;
        it = ne.find(v);
    }

    forr(i, 1, n+1) {
        lli lo = pos[i-1];
        lli hi = pos[i];

        while(lo != hi) {
            lli mid = lo+(hi-lo)/2;
            lli pv = mid - pos[i-1];
            lli nv = pos[i] - mid;
            auto it = po.lower_bound(pv+1);
            int v1 = 1e9;
            if(it != po.end()) {
                v1 = (*it).s;
            }
            it = ne.lower_bound(nv);
            int v2 = 1e9;
            if(it != ne.end()) {
                v2 = (*it).s;
            } 
            if(v2 < v1) {
                hi = mid;
            }
            else {
                lo = mid+1;
            }
        }
        lli l = lo;

        lo = pos[i];
        hi = pos[i+1];

        while(lo != hi) {
            lli mid = lo+(hi-lo+1)/2;
            lli pv = mid - pos[i];
            lli nv = pos[i+1] - mid;
            auto it = po.lower_bound(pv);
            int v1 = 1e9;
            if(it != po.end()) {
                v1 = (*it).s;
            }
            it = ne.lower_bound(nv+1);
            int v2 = 1e9;
            if(it != ne.end()) {
                v2 = (*it).s;
            } 
            if(v1 < v2) {
                lo = mid;
            }
            else {
                hi = mid-1;
            }
        }
        lli r = lo;
        printf("%lld\n", r-l);
    }
}

Compilation message

Main.cpp: In function 'void usaco()':
Main.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
Main.cpp:38:5: note: in expansion of macro 'scd'
   38 |     scd(n);
      |     ^~~
Main.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
Main.cpp:39:5: note: in expansion of macro 'scd'
   39 |     scd(q);
      |     ^~~
Main.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | #define sclld(t) scanf("%lld", &t)
      |                  ~~~~~^~~~~~~~~~~~
Main.cpp:44:18: note: in expansion of macro 'sclld'
   44 |     frange(i, n) sclld(pos[i+1]);
      |                  ^~~~~
Main.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | #define sclld(t) scanf("%lld", &t)
      |                  ~~~~~^~~~~~~~~~~~
Main.cpp:48:18: note: in expansion of macro 'sclld'
   48 |     frange(i, q) sclld(vec[i]);
      |                  ^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -