Submission #378155

# Submission time Handle Problem Language Result Execution time Memory
378155 2021-03-16T05:34:59 Z JerryLiu06 Strange Device (APIO19_strange_device) C++11
5 / 100
802 ms 69272 KB
#include <bits/stdc++.h>
#include <iostream>

using namespace std;

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

#define f first 
#define s second

int N; ll A, B, ans = 0; vector<pli> E;

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

    cin >> N >> A >> B; ll MOD = A * B; if (MOD < 0) MOD = 1 << 60; 

    for (int i = 0; i < N; i++) { ll X, Y; cin >> X >> Y; X %= MOD; Y %= MOD;
        if (X <= Y) { E.push_back({X, 1}); E.push_back({Y, -1}); }

        else { E.push_back({0, 1}); E.push_back({Y, -1}); E.push_back({X, 1}); E.push_back({MOD - 1, -1}); }
    }
    sort(begin(E), end(E)); int prev = 0; int cur = 0; ll PREV = 0; ll NOW = 0;
    
     for (int i = 0; i < E.size(); ) { ll NOW = E[i].f;
         while (i < E.size() && E[i].f == NOW) cur += E[i++].s; ans++;

         if (prev > 0) ans += E[i - 1].f - PREV - 1; prev = cur; PREV = NOW;
     }
    cout << ans << endl;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:17:65: warning: left shift count >= width of type [-Wshift-count-overflow]
   17 |     cin >> N >> A >> B; ll MOD = A * B; if (MOD < 0) MOD = 1 << 60;
      |                                                                 ^~
strange_device.cpp:26:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |      for (int i = 0; i < E.size(); ) { ll NOW = E[i].f;
      |                      ~~^~~~~~~~~~
strange_device.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |          while (i < E.size() && E[i].f == NOW) cur += E[i++].s; ans++;
      |                 ~~^~~~~~~~~~
strange_device.cpp:27:10: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   27 |          while (i < E.size() && E[i].f == NOW) cur += E[i++].s; ans++;
      |          ^~~~~
strange_device.cpp:27:65: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   27 |          while (i < E.size() && E[i].f == NOW) cur += E[i++].s; ans++;
      |                                                                 ^~~
strange_device.cpp:29:10: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   29 |          if (prev > 0) ans += E[i - 1].f - PREV - 1; prev = cur; PREV = NOW;
      |          ^~
strange_device.cpp:29:54: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   29 |          if (prev > 0) ans += E[i - 1].f - PREV - 1; prev = cur; PREV = NOW;
      |                                                      ^~~~
strange_device.cpp:24:72: warning: unused variable 'NOW' [-Wunused-variable]
   24 |     sort(begin(E), end(E)); int prev = 0; int cur = 0; ll PREV = 0; ll NOW = 0;
      |                                                                        ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 6 ms 1392 KB Output is correct
3 Correct 6 ms 1392 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 420 ms 57240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 632 ms 69012 KB Output is correct
3 Incorrect 571 ms 69036 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 632 ms 69012 KB Output is correct
3 Incorrect 571 ms 69036 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 632 ms 69012 KB Output is correct
3 Incorrect 571 ms 69036 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 68 ms 7392 KB Output is correct
3 Correct 63 ms 7516 KB Output is correct
4 Correct 802 ms 69120 KB Output is correct
5 Correct 63 ms 7396 KB Output is correct
6 Correct 63 ms 7392 KB Output is correct
7 Correct 63 ms 7532 KB Output is correct
8 Correct 64 ms 7516 KB Output is correct
9 Correct 61 ms 7392 KB Output is correct
10 Correct 65 ms 7392 KB Output is correct
11 Correct 65 ms 7392 KB Output is correct
12 Correct 61 ms 7700 KB Output is correct
13 Correct 65 ms 7408 KB Output is correct
14 Correct 695 ms 69272 KB Output is correct
15 Incorrect 65 ms 7392 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 6 ms 1392 KB Output is correct
3 Correct 6 ms 1392 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -