답안 #13249

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
13249 2015-02-05T14:39:16 Z tncks0121 돌 무게 재기 (IZhO11_stones) C++14
100 / 100
84 ms 5180 KB
#define _CRT_SECURE_NO_WARNINGS
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h> 
#include <time.h>
 
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
 
const int LEAF = 131072;
const int N_ = 100005;
 
int N;
 
struct node {
    int sum, tag;
    int mn, mx;
} Tree[LEAF+LEAF];
 
void spread (int nd, int len) {
    if(nd < LEAF) {
        for(int k = 0; k < 2; k++) {
            Tree[nd+nd+k].sum += Tree[nd].tag * (len/2);
            Tree[nd+nd+k].mn += Tree[nd].tag;
            Tree[nd+nd+k].mx += Tree[nd].tag;
            Tree[nd+nd+k].tag += Tree[nd].tag;
        }
        Tree[nd].tag = 0;
    }
}
 
void update (int nd, int nl, int nr, int x, int y, int d) {
    node &u = Tree[nd];
    int nmid = (nl + nr) >> 1;
 
    spread(nd, nr-nl+1);
 
    if(x <= nl && nr <= y) {
        u.sum += d * (nr-nl+1);
        u.mn += d;
        u.mx += d;
        u.tag += d;
        return;
    }
 
    if(x <= nmid)
        update(nd+nd, nl, nmid, x, min(y, nmid), d);
    if(y > nmid)
        update(nd+nd+1, nmid+1, nr, max(x, nmid+1), y, d);
     
    Tree[nd].sum = Tree[nd+nd].sum + Tree[nd+nd+1].sum;
    Tree[nd].mn = min(Tree[nd+nd].mn, Tree[nd+nd+1].mn);
    Tree[nd].mx = max(Tree[nd+nd].mx, Tree[nd+nd+1].mx);
    Tree[nd].tag = 0;
}
 
void update (int p, int d) {
    update(1, 1, LEAF, 1, p, d);
}
 
int main() {
    int i, j, k;
     
    scanf("%d", &N);
    while(N--) {
        int r, s; scanf("%d%d", &r, &s);
        int v = (s == 1) ? 1 : -1;
        update(r, v);
        bool h1 = (Tree[1].mn >= 0);
        bool h2 = (Tree[1].mx <= 0);
        putchar((h1 ^ h2) ? (h1 ? '>' : '<') : '?');
        putchar('\n');
        //printf("%d %d %d %d\n", Tree[1].mn, Tree[1].mx, h1, h2);
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5180 KB Output is correct - 73 tokens
2 Correct 0 ms 5180 KB Output is correct - 89 tokens
3 Correct 0 ms 5180 KB Output is correct - 221 tokens
4 Correct 0 ms 5180 KB Output is correct - 21 tokens
5 Correct 0 ms 5180 KB Output is correct - 369 tokens
6 Correct 0 ms 5180 KB Output is correct - 492 tokens
7 Correct 0 ms 5180 KB Output is correct - 945 tokens
8 Correct 0 ms 5180 KB Output is correct - 1237 tokens
9 Correct 0 ms 5180 KB Output is correct - 1105 tokens
10 Correct 5 ms 5180 KB Output is correct - 8921 tokens
11 Correct 48 ms 5180 KB Output is correct - 56110 tokens
12 Correct 72 ms 5180 KB Output is correct - 90207 tokens
13 Correct 81 ms 5180 KB Output is correct - 100000 tokens
14 Correct 77 ms 5180 KB Output is correct - 100000 tokens
15 Correct 80 ms 5180 KB Output is correct - 100000 tokens
16 Correct 78 ms 5180 KB Output is correct - 100000 tokens
17 Correct 84 ms 5180 KB Output is correct - 100000 tokens
18 Correct 75 ms 5180 KB Output is correct - 99999 tokens
19 Correct 75 ms 5180 KB Output is correct - 99999 tokens
20 Correct 72 ms 5180 KB Output is correct - 99999 tokens
21 Correct 74 ms 5180 KB Output is correct - 100000 tokens
22 Correct 72 ms 5180 KB Output is correct - 100000 tokens
23 Correct 72 ms 5180 KB Output is correct - 100000 tokens
24 Correct 64 ms 5180 KB Output is correct - 100000 tokens
25 Correct 68 ms 5180 KB Output is correct - 100000 tokens