Submission #396851

# Submission time Handle Problem Language Result Execution time Memory
396851 2021-04-30T19:49:00 Z duality Snowball (JOI21_ho_t2) C++11
0 / 100
1 ms 304 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int X[200000];
vplli v;
LLI ans[200000];
int main() {
    int i;
    int N,Q;
    LLI l = 0,r = 0,d = 0,W;
    scanf("%d %d",&N,&Q);
    for (i = 0; i < N; i++) scanf("%lld",&X[i]);
    v.pb(mp(0,0));
    for (i = 0; i < Q; i++) {
        scanf("%lld",&W);
        d += W;
        l = min(l,d),r = max(r,d);
        if (mp(-l,r) != v.back()) v.pb(mp(-l,r));
    }

    for (i = 0; i <= N; i++) {
        if (i == 0) ans[0] += v.back().first;
        else if (i == N) ans[N-1] += v.back().second;
        else {
            d = X[i]-X[i-1];
            int l = 0,r = v.size();
            while (l < r) {
                int m = (l+r) / 2;
                if (v[m].first+v[m].second > d) r = m;
                else l = m+1;
            }
            if (l == v.size()) ans[i-1] += v.back().second,ans[i] += v.back().first;
            else {
                if (v[l-1].first != v[l].first) ans[i-1] += v[l-1].second,ans[i] += d-v[l-1].second;
                else ans[i-1] += d-v[l-1].first,ans[i] += v[l-1].first;
            }
        }
    }
    for (i = 0; i < N; i++) printf("%lld\n",ans[i]);

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:66:39: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
   66 |     for (i = 0; i < N; i++) scanf("%lld",&X[i]);
      |                                    ~~~^  ~~~~~
      |                                       |  |
      |                                       |  int*
      |                                       long long int*
      |                                    %d
Main.cpp:86:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |             if (l == v.size()) ans[i-1] += v.back().second,ans[i] += v.back().first;
      |                 ~~^~~~~~~~~~~
Main.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |     scanf("%d %d",&N,&Q);
      |     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:66:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   66 |     for (i = 0; i < N; i++) scanf("%lld",&X[i]);
      |                             ~~~~~^~~~~~~~~~~~~~
Main.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   69 |         scanf("%lld",&W);
      |         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -