Submission #120013

#TimeUsernameProblemLanguageResultExecution timeMemory
120013E869120Editor (BOI15_edi)C++14
0 / 100
3048 ms32080 KiB
#include <iostream> #include <vector> #include <algorithm> #include <set> using namespace std; #pragma warning (disable: 4996) int N, A[1 << 19], G[1 << 19], level[1 << 19], par[1 << 19], maxlevel = 0; vector<int>I[1 << 19]; set<int>Set; int main() { scanf("%d", &N); for (int i = 1; i <= N; i++) { scanf("%d", &A[i]); level[i] = max(0, -A[i]); maxlevel = max(maxlevel, level[i]); I[level[i]].push_back(i); } for (int i = 1; i <= N; i++) Set.insert(i); for (int i = maxlevel; i >= 1; i--) { set<int>Set2; for (int j = 0; j < I[i].size(); j++) { auto itr = Set.lower_bound(I[i][j]); if (itr != Set.end() && (*itr) == I[i][j]) { Set.erase(I[i][j]); Set2.insert(I[i][j]); } } for (int j = 0; j < I[i].size(); j++) { auto itr = Set.lower_bound(I[i][j]); itr--; par[I[i][j]] = (*itr); auto itr2 = Set2.lower_bound(I[i][j]); if (itr2 != Set2.end() && (*itr2) == I[i][j]) Set.erase(par[I[i][j]]); } } for (int i = 1; i <= N; i++) { if (A[i] > 0) { G[i] = 1; } else { G[i] = 1; int cx = i; while (par[cx] != 0) { cx = par[cx]; G[cx] ^= 1; } } int ans = 0; for (int j = 1; j <= i; j++) { if (A[j] > 0 && G[j] == 1) ans = j; } printf("%d\n", A[ans]); } return 0; }

Compilation message (stderr)

edi.cpp:6:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning (disable: 4996)
 
edi.cpp: In function 'int main()':
edi.cpp:23:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < I[i].size(); j++) {
                   ~~^~~~~~~~~~~~~
edi.cpp:30:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < I[i].size(); j++) {
                   ~~^~~~~~~~~~~~~
edi.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
edi.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &A[i]);
   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...