답안 #380805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
380805 2021-03-23T03:31:20 Z JerryLiu06 Sails (IOI07_sails) C++11
0 / 100
1000 ms 13548 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, int> pii;

#define pb push_back

#define f first
#define s second

int N; ll MX; vector<pii> A; pii tree[400010];

void pushdown(int x, int l, int r) { int mid = (l + r) / 2;
    tree[x].f += tree[x].s;

    if (l < r) { tree[2 * x].s += tree[x].s; tree[2 * x + 1].s += tree[x].s; }
    
    tree[x].s = 0;
    
}
void update(int x, int l, int r, int tl, int tr) { int mid = (l + r) / 2;
    pushdown(x, l, r); if (r < tl || l > tr) return ; if (tl <= l && r <= tr) { tree[x].s++; return ; }

    update(2 * x, l, mid, tl, tr); update(2 * x + 1, mid + 1, r, tl, tr);

    pushdown(2 * x, l, mid); pushdown(2 * x + 1, mid + 1, r); tree[x].f = max(tree[2 * x].f, tree[2 * x + 1].f);
}
ll queryMax(int x, int l, int r, int tl, int tr) { int mid = (l + r) / 2;
    pushdown(x, l, r); if (r < tl || l > tr) return -1; if (tl <= l && r <= tr) return tree[x].f;

    return max(queryMax(2 * x, l, mid, tl, tr), queryMax(2 * x + 1, mid + 1, r, tl, tr));
}
ll queryPos(int x, int l, int r, int val) { int mid = (l + r) / 2;
    pushdown(x, l, r); if (l == r) return l;

    pushdown(2 * x, l, mid); pushdown(2 * x + 1, mid + 1, r);

    if (tree[2 * x + 1].f >= val) return queryPos(2 * x + 1, mid + 1, r, val);

    else if (tree[2 * x].f >= val) return queryPos(2 * x, l, mid, val); return 0;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> N; for (int i = 0; i < N; i++) { pii P; cin >> P.f >> P.s; A.pb(P); MX = max(MX, P.f); }

    sort(A.begin(), A.end()); for (pii P : A) { 
        
        int FIRST = P.f - P.s + 1; int CUR = queryMax(1, 1, MX, FIRST, FIRST);

        int END = min(queryPos(1, 1, MX, CUR) + 1, P.f + 1); int START = queryPos(1, 1, MX, CUR + 1) + 1;
        
        update(1, 1, MX, END, P.f); update(1, 1, MX, START, P.s - P.f + END + START - 2);
        
        for (int i = 1; i <= MX; i++) cout << queryMax(1, 1, MX, i, i) << " "; cout << "\n";
    }
    ll ans = 0; for (int i = 1; i <= MX; i++) { ll CUR = queryMax(1, 1, MX, i, i); ans += (CUR * (CUR - 1)) / 2; } cout << ans;
}

Compilation message

sails.cpp: In function 'void pushdown(int, int, int)':
sails.cpp:15:42: warning: unused variable 'mid' [-Wunused-variable]
   15 | void pushdown(int x, int l, int r) { int mid = (l + r) / 2;
      |                                          ^~~
sails.cpp: In function 'll queryPos(int, int, int, int)':
sails.cpp:42:5: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   42 |     else if (tree[2 * x].f >= val) return queryPos(2 * x, l, mid, val); return 0;
      |     ^~~~
sails.cpp:42:73: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   42 |     else if (tree[2 * x].f >= val) return queryPos(2 * x, l, mid, val); return 0;
      |                                                                         ^~~~~~
sails.cpp: In function 'int main()':
sails.cpp:58:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   58 |         for (int i = 1; i <= MX; i++) cout << queryMax(1, 1, MX, i, i) << " "; cout << "\n";
      |         ^~~
sails.cpp:58:80: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   58 |         for (int i = 1; i <= MX; i++) cout << queryMax(1, 1, MX, i, i) << " "; cout << "\n";
      |                                                                                ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 12524 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 9196 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1096 ms 8940 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 10216 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1095 ms 13548 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1085 ms 13284 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1084 ms 13324 KB Time limit exceeded
2 Halted 0 ms 0 KB -