답안 #284144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
284144 2020-08-26T23:11:49 Z Ozy 벽 (IOI14_wall) C++17
24 / 100
606 ms 49320 KB
#include "wall.h"
#include <bits/stdc++.h>

#define lli long long int
#define rep(i,a,b) for (lli i = (a); i <= (b); i++)
#define MIN -100001

using namespace std;

struct x{
    lli pos;
    lli tipo;
    lli val;

    bool operator < (const x &a)
    const {
        return pos < a.pos;
    }
};

set<lli> set1,set2;
vector<x> sum,res;
lli cant1[100002],cant2[100002];
lli cont1,cont2,a,b;

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){

    rep (i,0,k-1) {
        if (op[i] == 1) {
            //agrega
            sum.push_back({left[i],1,height[i]});
            sum.push_back({right[i]+1,0,height[i]});
        }
        else {
            //quita
            res.push_back({left[i],1,height[i]});
            res.push_back({right[i]+1,0,height[i]});
        }
    }

    sort(sum.begin(), sum.end());
    sort(res.begin(), res.end());

    cont1 = 0;
    cont2 = 0;
    rep(i,0,n-1) {

        while (cont1 < sum.size() && sum[cont1].pos == i) {
            if (sum[cont1].tipo == 1) {

                cant1[sum[cont1].val] ++;
                if (cant1[sum[cont1].val] == 1) set1.insert(sum[cont1].val);

            }
            else {

                cant1[sum[cont1].val]--;
                if (cant1[sum[cont1].val] == 0) set1.erase(sum[cont1].val);

            }

            cont1++;
        }


        while (cont2 < res.size() && res[cont2].pos == i) {
            if (res[cont2].tipo == 1) {

                cant2[res[cont2].val] ++;
                if (cant2[res[cont2].val] == 1) set2.insert(res[cont2].val);

            }
            else {

                cant2[res[cont2].val]--;
                if (cant2[res[cont2].val] == 0) set2.erase(res[cont2].val);

            }

            cont2++;
        }

        if (!set1.empty()) a = (*set1.rbegin());
        else a = 0;
        if (!set2.empty()) b = (*set2.begin());
        else b = -MIN;

        finalHeight[i] = min(a,b);

    }

    return;
}

Compilation message

wall.cpp: In function 'void buildWall(int, int, int*, int*, int*, int*, int*)':
wall.cpp:48:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<x>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         while (cont1 < sum.size() && sum[cont1].pos == i) {
      |                ~~~~~~^~~~~~~~~~~~
wall.cpp:66:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<x>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         while (cont2 < res.size() && res[cont2].pos == i) {
      |                ~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Incorrect 5 ms 2560 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 300 ms 46896 KB Output is correct
3 Correct 229 ms 22092 KB Output is correct
4 Correct 606 ms 49320 KB Output is correct
5 Correct 302 ms 44464 KB Output is correct
6 Correct 291 ms 49076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Incorrect 5 ms 2560 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Incorrect 6 ms 2560 KB Output isn't correct
3 Halted 0 ms 0 KB -