답안 #521201

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521201 2022-02-01T08:06:10 Z cadmiumsky Sails (IOI07_sails) C++14
40 / 100
1000 ms 1624 KB
#include <bits/stdc++.h>

using namespace std;
const int nmax = 1e5 + 5;

#define ll long long

namespace Slope {
  multiset<int> slope;
  int val0;
  int last;
  void init() {
    slope.insert(0);
    val0 = 1;
    last = 0;
    return;
  }
  void insert(int l, int k) {
    //cout << l << ' ' << k << '\n';
    if(k == 0)
      return;
    if(last < l) {
      while(slope.size() < val0) {
        slope.insert(last + 1);
      }
      last = l;
    }
    auto it = upper_bound(slope.begin(), slope.end(), l - k), lst = it;
    lst--;
    bool ok = 0;
    if(*lst == 0) {
      val0++;
      ok = 1;
    }
    int decr = k;
    if(it != slope.end())
      decr = *it - (l - k);
    int temp = *lst;
    slope.erase(lst);
    if(it != slope.end())
      slope.erase(it), slope.insert(l);
    slope.insert(temp + decr);
    if(ok)
      slope.insert(0);
    
    //cout << val0 << '\n';
    //for(auto x : slope) 
      //cout << x << ' ';
    //cout << '\n';
  }
  void calculate() {
    ll sum = 0;
    for(int i = 1; i <= last; i++) {
      while(slope.size() && *slope.begin() < i)
        val0--, slope.erase(slope.begin());
      //cout << i << ' ' << val0 << '\n';
      sum += (ll)val0 * (val0 - 1) / 2LL;
    }
    #undef it
    cout << sum << '\n';
    return;
  }
}

pair<int,int> v[nmax];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
  }
  sort(v, v + n);
  Slope::init();
  for(int i = 0; i < n; i++)
    Slope::insert(v[i].first, v[i].second);
  Slope::calculate();
  return 0;
}

Compilation message

sails.cpp: In function 'void Slope::insert(int, int)':
sails.cpp:23:26: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |       while(slope.size() < val0) {
      |             ~~~~~~~~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 368 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 416 KB Output is correct
2 Execution timed out 1093 ms 1228 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1081 ms 1236 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1082 ms 996 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1083 ms 1344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 1624 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1098 ms 1336 KB Time limit exceeded
2 Halted 0 ms 0 KB -