Submission #124381

# Submission time Handle Problem Language Result Execution time Memory
124381 2019-07-03T08:58:33 Z AyaBenSaad Strange Device (APIO19_strange_device) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define ll long long 

using namespace std;

const int M = 1e6 + 6;
int n;
ll a, b
stack <pair <ll, ll> > s;
pair <ll, ll> t[M];

bool inter (ll a, ll b) {
  ll x = s.top().first;
  ll y = s.top().second;
  return ((a <= y && a >= x) || (b <= y && b >= x));
}
  
int main () {
  scanf ("%d %lld %lld", &n, &a, &b);
  for (int i = 0; i < n; i++) {
    scanf ("%lld %lld", &t[i].first, &t[i].second);
  }
  sort (t, t+n);
  for (int i = 0; i < n; i++) {
    if (s.empty() || !inter(t[i].first, t[i].second)) {
      s.push ({t[i].first, t[i].second});
    }
    else {
      int x = min (t[i].first, s.top().first);
      int y = max (t[i].second, s.top().second);
      s.pop();
      s.push({x, y});
    }
  }
  long long ans = 0;
  while (s.size()) {
    ans += s.top().second - s.top().first;
    s.pop();
  }
  printf ("%lld\n", ans);
}

Compilation message

strange_device.cpp:9:1: error: expected initializer before 'stack'
 stack <pair <ll, ll> > s;
 ^~~~~
strange_device.cpp: In function 'bool inter(long long int, long long int)':
strange_device.cpp:13:10: error: 's' was not declared in this scope
   ll x = s.top().first;
          ^
strange_device.cpp: In function 'int main()':
strange_device.cpp:19:35: error: 'b' was not declared in this scope
   scanf ("%d %lld %lld", &n, &a, &b);
                                   ^
strange_device.cpp:25:9: error: 's' was not declared in this scope
     if (s.empty() || !inter(t[i].first, t[i].second)) {
         ^
strange_device.cpp:36:10: error: 's' was not declared in this scope
   while (s.size()) {
          ^
strange_device.cpp:21:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%lld %lld", &t[i].first, &t[i].second);
     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~