답안 #396853

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
396853 2021-04-30T19:51:02 Z duality Snowball (JOI21_ho_t2) C++11
100 / 100
132 ms 13864 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 ----------

LLI 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: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);
      |         ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 328 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 452 KB Output is correct
16 Correct 2 ms 464 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 328 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 452 KB Output is correct
16 Correct 2 ms 464 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 42 ms 6144 KB Output is correct
21 Correct 40 ms 5988 KB Output is correct
22 Correct 37 ms 5960 KB Output is correct
23 Correct 36 ms 5820 KB Output is correct
24 Correct 43 ms 6016 KB Output is correct
25 Correct 131 ms 11908 KB Output is correct
26 Correct 128 ms 11784 KB Output is correct
27 Correct 131 ms 11304 KB Output is correct
28 Correct 128 ms 11128 KB Output is correct
29 Correct 119 ms 9392 KB Output is correct
30 Correct 98 ms 7352 KB Output is correct
31 Correct 81 ms 6724 KB Output is correct
32 Correct 76 ms 6844 KB Output is correct
33 Correct 12 ms 1480 KB Output is correct
34 Correct 112 ms 9224 KB Output is correct
35 Correct 112 ms 8892 KB Output is correct
36 Correct 132 ms 11844 KB Output is correct
37 Correct 125 ms 10800 KB Output is correct
38 Correct 126 ms 11304 KB Output is correct
39 Correct 125 ms 11432 KB Output is correct
40 Correct 100 ms 11432 KB Output is correct
41 Correct 42 ms 6580 KB Output is correct
42 Correct 77 ms 7024 KB Output is correct
43 Correct 105 ms 13448 KB Output is correct
44 Correct 42 ms 6380 KB Output is correct
45 Correct 97 ms 11432 KB Output is correct
46 Correct 107 ms 13564 KB Output is correct
47 Correct 109 ms 11696 KB Output is correct
48 Correct 110 ms 13864 KB Output is correct