Submission #187159

#TimeUsernameProblemLanguageResultExecution timeMemory
187159Ruxandra985Alternating Current (BOI18_alternating)C++14
0 / 100
65 ms9972 KiB
#include <bits/stdc++.h> #define DIMN 100010 using namespace std; pair <int,pair <int,int> > v[DIMN],w[DIMN]; int sol[DIMN] , par[DIMN] , sp1[DIMN] , sp2[DIMN]; set <pair <int,int> > s; int main() { FILE *fin = stdin; FILE *fout = stdout; int n , m , i , maxi , poz, poz2 , maxi2, ed , ok; fscanf (fin,"%d%d",&n,&m); maxi = 0; poz = 0; for (i=1;i<=m;i++){ fscanf (fin,"%d%d",&v[i].first,&v[i].second.first); v[i].second.second = i; w[i] = v[i]; } maxi2 = 0; poz2 = 0; sort (v + 1 , v + m + 1); for (i=1;i<=m;i++){ if (v[i].first > v[i].second.first && maxi < v[i].second.first){ maxi = v[i].second.first; poz = i; } } for (i=1;i<=m;i++){ /// check daca i e inclus total in vreun alt interval if (v[i].first <= v[i].second.first){ /// e un interval normal if (maxi > v[i].second.first){ /// e inclus par[i] = poz; continue; } else{ maxi = v[i].second.first; poz = i; } } else { maxi = n; /// le tratezi ca pe doua intervale poz = i; if (maxi2 > v[i].second.first){ /// e inclus par[i] = poz2; continue; } else { maxi2 = v[i].second.first; poz2 = i; } } par[i] = -1; /// e tata } /// daca au ceva in comun, pui semne opuse ed = 0; ok = 0; for (i=1;i<=m;i++){ if (par[i] == -1){ if (v[i].first > v[i].second.first){ if (!ok){ if (ed < v[i].first) sol[v[i].second.second] = 0; else { /// vreau sa il gasesc pe tatal lui, care e unic /// intervalul al carui sfarsit e cel mai mic mai are decat inc while (!s.empty() && v[i].first > s.begin()->first){ s.erase(s.begin()); } sol[v[i].second.second] = 1 - sol[s.begin()->second]; } s.insert(make_pair(v[i].second.first , v[i].second.second)); ed = max(ed , v[i].second.first); } else { sol[v[i].second.second] = 1 - sol[v[ok].second.second]; } ok = i; } else if (ed < v[i].first) sol[v[i].second.second] = 0; else { /// vreau sa il gasesc pe tatal lui, care e unic /// intervalul al carui sfarsit e cel mai mic mai are decat inc while (!s.empty() && v[i].first > s.begin()->first){ s.erase(s.begin()); } sol[v[i].second.second] = 1 - sol[s.begin()->second]; } s.insert(make_pair(v[i].second.first , v[i].second.second)); ed = v[i].second.first; } else { sol[v[i].second.second] = 1 - sol[v[par[i]].second.second]; } } for (i=1;i<=m;i++){ if (w[i].first <= w[i].second.first){ if (sol[i] == 1){ sp1[w[i].first]++; sp1[w[i].second.first+1]--; } else { sp2[w[i].first]++; sp2[w[i].second.first+1]--; } } else { if (sol[i] == 1){ sp1[w[i].first]++; sp1[1]++; sp1[w[i].second.first+1]--; } else { sp2[w[i].first]++; sp2[1]++; sp2[w[i].second.first+1]--; } } } for (i=1;i<=n;i++){ sp1[i] += sp1[i-1]; sp2[i] += sp2[i-1]; if (!sp1[i] || !sp2[i]){ fprintf (fout,"impossible"); return 0; } } for (i=1;i<=m;i++){ fprintf (fout,"%d",sol[i]); } return 0; }

Compilation message (stderr)

alternating.cpp: In function 'int main()':
alternating.cpp:12:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d%d",&n,&m);
     ~~~~~~~^~~~~~~~~~~~~~~~~~
alternating.cpp:16:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d%d",&v[i].first,&v[i].second.first);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...