Submission #132114

# Submission time Handle Problem Language Result Execution time Memory
132114 2019-07-18T10:13:16 Z TadijaSebez Alternating Current (BOI18_alternating) C++11
100 / 100
483 ms 16240 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=100050;
const int M=2*N;
const int inf=1e9+7;
int ls[M],rs[M],tsz,root,lzy[M],mn[M],n,m;
void Set(int &c, int ss, int se, int qs, int qe, int f)
{
	if(qs>se || ss>qe) return;
	if(!c) c=++tsz;
	if(qs<=ss && qe>=se){ lzy[c]+=f;mn[c]+=f;return;}
	int mid=ss+se>>1;
	Set(ls[c],ss,mid,qs,qe,f);
	Set(rs[c],mid+1,se,qs,qe,f);
	mn[c]=min(mn[ls[c]],mn[rs[c]])+lzy[c];
}
void Set(int l, int r, int f)
{
	if(l>r)
	{
		Set(root,1,n,1,r,f);
		Set(root,1,n,l,n,f);
	}
	else Set(root,1,n,l,r,f);
}
int Get(int c, int ss, int se, int qs, int qe)
{
	if(qs>se || ss>qe) return inf;
	if(qs<=ss && qe>=se) return mn[c];
	int mid=ss+se>>1;
	return min(Get(ls[c],ss,mid,qs,qe),Get(rs[c],mid+1,se,qs,qe))+lzy[c];
}
int Get(int l, int r)
{
	if(l>r) return min(Get(root,1,n,1,r),Get(root,1,n,l,n));
	return Get(root,1,n,l,r);
}
int l[N],r[N];
vector<int> events[N],E[N];
void AddEdge(int u, int v){ E[u].pb(v);E[v].pb(u);}
int col[N];
bool was[N];
void DFS(int u)
{
	was[u]=1;
	for(int v:E[u])
	{
		if(!was[v])
		{
			col[v]=col[u]^1;
			DFS(v);
		}
		else if(col[u]==col[v])
		{
			printf("impossible\n");
			exit(0);
		}
	}
}
int main()
{
	scanf("%i %i",&n,&m);
	set<int> active;
	for(int i=1;i<=m;i++)
	{
		scanf("%i %i",&l[i],&r[i]);
		events[l[i]].pb(i);
		events[r[i]+1].pb(i);
		if(l[i]>r[i]) active.insert(i);
	}
    for(int i=1;i<=n;i++)
	{
		for(int j:events[i])
		{
			if(active.count(j)) active.erase(j);
			else active.insert(j);
		}
		if(active.size()<2) return 0*printf("impossible\n");
		if(active.size()==2) AddEdge(*active.begin(),*active.rbegin());
	}
	for(int i=1;i<=m;i++) if(!was[i]) DFS(i);
	for(int i=1;i<=m;i++) if(!col[i]) Set(l[i],r[i],1);
	for(int i=1;i<=m;i++)
	{
		if(col[i]) printf("0");
		else
		{
			if(Get(l[i],r[i])==1) printf("1");
			else
			{
				printf("0");
				Set(l[i],r[i],-1);
			}
		}
	}
	return 0;
}

Compilation message

alternating.cpp: In function 'void Set(int&, int, int, int, int, int)':
alternating.cpp:13:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
alternating.cpp: In function 'int Get(int, int, int, int, int)':
alternating.cpp:31:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
alternating.cpp: In function 'int main()':
alternating.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
alternating.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i %i",&l[i],&r[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5116 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 6 ms 4984 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 5112 KB Output is correct
7 Correct 7 ms 5112 KB Output is correct
8 Correct 8 ms 5112 KB Output is correct
9 Correct 8 ms 5112 KB Output is correct
10 Correct 7 ms 5116 KB Output is correct
11 Correct 6 ms 4984 KB Output is correct
12 Correct 7 ms 5112 KB Output is correct
13 Correct 8 ms 4984 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 6 ms 4988 KB Output is correct
16 Correct 6 ms 5112 KB Output is correct
17 Correct 6 ms 4984 KB Output is correct
18 Correct 6 ms 5112 KB Output is correct
19 Correct 6 ms 5112 KB Output is correct
20 Correct 6 ms 5112 KB Output is correct
21 Correct 7 ms 5112 KB Output is correct
22 Correct 9 ms 5112 KB Output is correct
23 Correct 7 ms 5112 KB Output is correct
24 Correct 6 ms 4984 KB Output is correct
25 Correct 6 ms 5032 KB Output is correct
26 Correct 6 ms 4984 KB Output is correct
27 Correct 6 ms 5072 KB Output is correct
28 Correct 6 ms 5112 KB Output is correct
29 Correct 6 ms 5112 KB Output is correct
30 Correct 6 ms 4984 KB Output is correct
31 Correct 6 ms 4984 KB Output is correct
32 Correct 6 ms 5116 KB Output is correct
33 Correct 6 ms 5116 KB Output is correct
34 Correct 6 ms 4984 KB Output is correct
35 Correct 7 ms 5104 KB Output is correct
36 Correct 6 ms 5112 KB Output is correct
37 Correct 6 ms 4984 KB Output is correct
38 Correct 8 ms 4984 KB Output is correct
39 Correct 6 ms 5112 KB Output is correct
40 Correct 6 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5116 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 6 ms 4984 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 5112 KB Output is correct
7 Correct 7 ms 5112 KB Output is correct
8 Correct 8 ms 5112 KB Output is correct
9 Correct 8 ms 5112 KB Output is correct
10 Correct 7 ms 5116 KB Output is correct
11 Correct 6 ms 4984 KB Output is correct
12 Correct 7 ms 5112 KB Output is correct
13 Correct 8 ms 4984 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 6 ms 4988 KB Output is correct
16 Correct 6 ms 5112 KB Output is correct
17 Correct 6 ms 4984 KB Output is correct
18 Correct 6 ms 5112 KB Output is correct
19 Correct 6 ms 5112 KB Output is correct
20 Correct 6 ms 5112 KB Output is correct
21 Correct 7 ms 5112 KB Output is correct
22 Correct 9 ms 5112 KB Output is correct
23 Correct 7 ms 5112 KB Output is correct
24 Correct 6 ms 4984 KB Output is correct
25 Correct 6 ms 5032 KB Output is correct
26 Correct 6 ms 4984 KB Output is correct
27 Correct 6 ms 5072 KB Output is correct
28 Correct 6 ms 5112 KB Output is correct
29 Correct 6 ms 5112 KB Output is correct
30 Correct 6 ms 4984 KB Output is correct
31 Correct 6 ms 4984 KB Output is correct
32 Correct 6 ms 5116 KB Output is correct
33 Correct 6 ms 5116 KB Output is correct
34 Correct 6 ms 4984 KB Output is correct
35 Correct 7 ms 5104 KB Output is correct
36 Correct 6 ms 5112 KB Output is correct
37 Correct 6 ms 4984 KB Output is correct
38 Correct 8 ms 4984 KB Output is correct
39 Correct 6 ms 5112 KB Output is correct
40 Correct 6 ms 4984 KB Output is correct
41 Correct 6 ms 5112 KB Output is correct
42 Correct 6 ms 4984 KB Output is correct
43 Correct 6 ms 5112 KB Output is correct
44 Correct 6 ms 5004 KB Output is correct
45 Correct 6 ms 5112 KB Output is correct
46 Correct 6 ms 5112 KB Output is correct
47 Correct 6 ms 4984 KB Output is correct
48 Correct 6 ms 4984 KB Output is correct
49 Correct 6 ms 5112 KB Output is correct
50 Correct 6 ms 5112 KB Output is correct
51 Correct 6 ms 4984 KB Output is correct
52 Correct 6 ms 5112 KB Output is correct
53 Correct 6 ms 4984 KB Output is correct
54 Correct 6 ms 5032 KB Output is correct
55 Correct 6 ms 4984 KB Output is correct
56 Correct 6 ms 5112 KB Output is correct
57 Correct 6 ms 4984 KB Output is correct
58 Correct 6 ms 5112 KB Output is correct
59 Correct 6 ms 5112 KB Output is correct
60 Correct 6 ms 5112 KB Output is correct
61 Correct 6 ms 5112 KB Output is correct
62 Correct 6 ms 4984 KB Output is correct
63 Correct 6 ms 5112 KB Output is correct
64 Correct 6 ms 4988 KB Output is correct
65 Correct 7 ms 5112 KB Output is correct
66 Correct 6 ms 5112 KB Output is correct
67 Correct 7 ms 5112 KB Output is correct
68 Correct 7 ms 4984 KB Output is correct
69 Correct 6 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5116 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 6 ms 4984 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 5112 KB Output is correct
7 Correct 7 ms 5112 KB Output is correct
8 Correct 8 ms 5112 KB Output is correct
9 Correct 8 ms 5112 KB Output is correct
10 Correct 7 ms 5116 KB Output is correct
11 Correct 6 ms 4984 KB Output is correct
12 Correct 7 ms 5112 KB Output is correct
13 Correct 8 ms 4984 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 6 ms 4988 KB Output is correct
16 Correct 6 ms 5112 KB Output is correct
17 Correct 6 ms 4984 KB Output is correct
18 Correct 6 ms 5112 KB Output is correct
19 Correct 6 ms 5112 KB Output is correct
20 Correct 6 ms 5112 KB Output is correct
21 Correct 7 ms 5112 KB Output is correct
22 Correct 9 ms 5112 KB Output is correct
23 Correct 7 ms 5112 KB Output is correct
24 Correct 6 ms 4984 KB Output is correct
25 Correct 6 ms 5032 KB Output is correct
26 Correct 6 ms 4984 KB Output is correct
27 Correct 6 ms 5072 KB Output is correct
28 Correct 6 ms 5112 KB Output is correct
29 Correct 6 ms 5112 KB Output is correct
30 Correct 6 ms 4984 KB Output is correct
31 Correct 6 ms 4984 KB Output is correct
32 Correct 6 ms 5116 KB Output is correct
33 Correct 6 ms 5116 KB Output is correct
34 Correct 6 ms 4984 KB Output is correct
35 Correct 7 ms 5104 KB Output is correct
36 Correct 6 ms 5112 KB Output is correct
37 Correct 6 ms 4984 KB Output is correct
38 Correct 8 ms 4984 KB Output is correct
39 Correct 6 ms 5112 KB Output is correct
40 Correct 6 ms 4984 KB Output is correct
41 Correct 6 ms 5112 KB Output is correct
42 Correct 6 ms 4984 KB Output is correct
43 Correct 6 ms 5112 KB Output is correct
44 Correct 6 ms 5004 KB Output is correct
45 Correct 6 ms 5112 KB Output is correct
46 Correct 6 ms 5112 KB Output is correct
47 Correct 6 ms 4984 KB Output is correct
48 Correct 6 ms 4984 KB Output is correct
49 Correct 6 ms 5112 KB Output is correct
50 Correct 6 ms 5112 KB Output is correct
51 Correct 6 ms 4984 KB Output is correct
52 Correct 6 ms 5112 KB Output is correct
53 Correct 6 ms 4984 KB Output is correct
54 Correct 6 ms 5032 KB Output is correct
55 Correct 6 ms 4984 KB Output is correct
56 Correct 6 ms 5112 KB Output is correct
57 Correct 6 ms 4984 KB Output is correct
58 Correct 6 ms 5112 KB Output is correct
59 Correct 6 ms 5112 KB Output is correct
60 Correct 6 ms 5112 KB Output is correct
61 Correct 6 ms 5112 KB Output is correct
62 Correct 6 ms 4984 KB Output is correct
63 Correct 6 ms 5112 KB Output is correct
64 Correct 6 ms 4988 KB Output is correct
65 Correct 7 ms 5112 KB Output is correct
66 Correct 6 ms 5112 KB Output is correct
67 Correct 7 ms 5112 KB Output is correct
68 Correct 7 ms 4984 KB Output is correct
69 Correct 6 ms 5112 KB Output is correct
70 Correct 6 ms 5240 KB Output is correct
71 Correct 7 ms 5240 KB Output is correct
72 Correct 6 ms 5112 KB Output is correct
73 Correct 6 ms 5112 KB Output is correct
74 Correct 6 ms 5112 KB Output is correct
75 Correct 6 ms 5112 KB Output is correct
76 Correct 7 ms 5112 KB Output is correct
77 Correct 8 ms 5112 KB Output is correct
78 Correct 7 ms 4984 KB Output is correct
79 Correct 8 ms 5112 KB Output is correct
80 Correct 6 ms 5112 KB Output is correct
81 Correct 7 ms 5112 KB Output is correct
82 Correct 7 ms 5112 KB Output is correct
83 Correct 7 ms 5240 KB Output is correct
84 Correct 7 ms 5112 KB Output is correct
85 Correct 6 ms 5112 KB Output is correct
86 Correct 6 ms 5240 KB Output is correct
87 Correct 7 ms 5112 KB Output is correct
88 Correct 6 ms 5112 KB Output is correct
89 Correct 6 ms 5112 KB Output is correct
90 Correct 8 ms 5112 KB Output is correct
91 Correct 6 ms 5112 KB Output is correct
92 Correct 7 ms 5112 KB Output is correct
93 Correct 6 ms 5112 KB Output is correct
94 Correct 6 ms 4984 KB Output is correct
95 Correct 6 ms 5112 KB Output is correct
96 Correct 7 ms 5112 KB Output is correct
97 Correct 7 ms 5084 KB Output is correct
98 Correct 7 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 12524 KB Output is correct
2 Correct 9 ms 5920 KB Output is correct
3 Correct 25 ms 9080 KB Output is correct
4 Correct 114 ms 14024 KB Output is correct
5 Correct 143 ms 15224 KB Output is correct
6 Correct 62 ms 9852 KB Output is correct
7 Correct 145 ms 15756 KB Output is correct
8 Correct 14 ms 6392 KB Output is correct
9 Correct 10 ms 6008 KB Output is correct
10 Correct 149 ms 15616 KB Output is correct
11 Correct 145 ms 13816 KB Output is correct
12 Correct 153 ms 16240 KB Output is correct
13 Correct 9 ms 6044 KB Output is correct
14 Correct 10 ms 6008 KB Output is correct
15 Correct 166 ms 11768 KB Output is correct
16 Correct 52 ms 11512 KB Output is correct
17 Correct 385 ms 14816 KB Output is correct
18 Correct 244 ms 10760 KB Output is correct
19 Correct 9 ms 5496 KB Output is correct
20 Correct 76 ms 13560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5116 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 6 ms 4984 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 5112 KB Output is correct
7 Correct 7 ms 5112 KB Output is correct
8 Correct 8 ms 5112 KB Output is correct
9 Correct 8 ms 5112 KB Output is correct
10 Correct 7 ms 5116 KB Output is correct
11 Correct 6 ms 4984 KB Output is correct
12 Correct 7 ms 5112 KB Output is correct
13 Correct 8 ms 4984 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 6 ms 4988 KB Output is correct
16 Correct 6 ms 5112 KB Output is correct
17 Correct 6 ms 4984 KB Output is correct
18 Correct 6 ms 5112 KB Output is correct
19 Correct 6 ms 5112 KB Output is correct
20 Correct 6 ms 5112 KB Output is correct
21 Correct 7 ms 5112 KB Output is correct
22 Correct 9 ms 5112 KB Output is correct
23 Correct 7 ms 5112 KB Output is correct
24 Correct 6 ms 4984 KB Output is correct
25 Correct 6 ms 5032 KB Output is correct
26 Correct 6 ms 4984 KB Output is correct
27 Correct 6 ms 5072 KB Output is correct
28 Correct 6 ms 5112 KB Output is correct
29 Correct 6 ms 5112 KB Output is correct
30 Correct 6 ms 4984 KB Output is correct
31 Correct 6 ms 4984 KB Output is correct
32 Correct 6 ms 5116 KB Output is correct
33 Correct 6 ms 5116 KB Output is correct
34 Correct 6 ms 4984 KB Output is correct
35 Correct 7 ms 5104 KB Output is correct
36 Correct 6 ms 5112 KB Output is correct
37 Correct 6 ms 4984 KB Output is correct
38 Correct 8 ms 4984 KB Output is correct
39 Correct 6 ms 5112 KB Output is correct
40 Correct 6 ms 4984 KB Output is correct
41 Correct 6 ms 5112 KB Output is correct
42 Correct 6 ms 4984 KB Output is correct
43 Correct 6 ms 5112 KB Output is correct
44 Correct 6 ms 5004 KB Output is correct
45 Correct 6 ms 5112 KB Output is correct
46 Correct 6 ms 5112 KB Output is correct
47 Correct 6 ms 4984 KB Output is correct
48 Correct 6 ms 4984 KB Output is correct
49 Correct 6 ms 5112 KB Output is correct
50 Correct 6 ms 5112 KB Output is correct
51 Correct 6 ms 4984 KB Output is correct
52 Correct 6 ms 5112 KB Output is correct
53 Correct 6 ms 4984 KB Output is correct
54 Correct 6 ms 5032 KB Output is correct
55 Correct 6 ms 4984 KB Output is correct
56 Correct 6 ms 5112 KB Output is correct
57 Correct 6 ms 4984 KB Output is correct
58 Correct 6 ms 5112 KB Output is correct
59 Correct 6 ms 5112 KB Output is correct
60 Correct 6 ms 5112 KB Output is correct
61 Correct 6 ms 5112 KB Output is correct
62 Correct 6 ms 4984 KB Output is correct
63 Correct 6 ms 5112 KB Output is correct
64 Correct 6 ms 4988 KB Output is correct
65 Correct 7 ms 5112 KB Output is correct
66 Correct 6 ms 5112 KB Output is correct
67 Correct 7 ms 5112 KB Output is correct
68 Correct 7 ms 4984 KB Output is correct
69 Correct 6 ms 5112 KB Output is correct
70 Correct 6 ms 5240 KB Output is correct
71 Correct 7 ms 5240 KB Output is correct
72 Correct 6 ms 5112 KB Output is correct
73 Correct 6 ms 5112 KB Output is correct
74 Correct 6 ms 5112 KB Output is correct
75 Correct 6 ms 5112 KB Output is correct
76 Correct 7 ms 5112 KB Output is correct
77 Correct 8 ms 5112 KB Output is correct
78 Correct 7 ms 4984 KB Output is correct
79 Correct 8 ms 5112 KB Output is correct
80 Correct 6 ms 5112 KB Output is correct
81 Correct 7 ms 5112 KB Output is correct
82 Correct 7 ms 5112 KB Output is correct
83 Correct 7 ms 5240 KB Output is correct
84 Correct 7 ms 5112 KB Output is correct
85 Correct 6 ms 5112 KB Output is correct
86 Correct 6 ms 5240 KB Output is correct
87 Correct 7 ms 5112 KB Output is correct
88 Correct 6 ms 5112 KB Output is correct
89 Correct 6 ms 5112 KB Output is correct
90 Correct 8 ms 5112 KB Output is correct
91 Correct 6 ms 5112 KB Output is correct
92 Correct 7 ms 5112 KB Output is correct
93 Correct 6 ms 5112 KB Output is correct
94 Correct 6 ms 4984 KB Output is correct
95 Correct 6 ms 5112 KB Output is correct
96 Correct 7 ms 5112 KB Output is correct
97 Correct 7 ms 5084 KB Output is correct
98 Correct 7 ms 5112 KB Output is correct
99 Correct 75 ms 12524 KB Output is correct
100 Correct 9 ms 5920 KB Output is correct
101 Correct 25 ms 9080 KB Output is correct
102 Correct 114 ms 14024 KB Output is correct
103 Correct 143 ms 15224 KB Output is correct
104 Correct 62 ms 9852 KB Output is correct
105 Correct 145 ms 15756 KB Output is correct
106 Correct 14 ms 6392 KB Output is correct
107 Correct 10 ms 6008 KB Output is correct
108 Correct 149 ms 15616 KB Output is correct
109 Correct 145 ms 13816 KB Output is correct
110 Correct 153 ms 16240 KB Output is correct
111 Correct 9 ms 6044 KB Output is correct
112 Correct 10 ms 6008 KB Output is correct
113 Correct 166 ms 11768 KB Output is correct
114 Correct 52 ms 11512 KB Output is correct
115 Correct 385 ms 14816 KB Output is correct
116 Correct 244 ms 10760 KB Output is correct
117 Correct 9 ms 5496 KB Output is correct
118 Correct 76 ms 13560 KB Output is correct
119 Correct 9 ms 6136 KB Output is correct
120 Correct 113 ms 15432 KB Output is correct
121 Correct 80 ms 11512 KB Output is correct
122 Correct 7 ms 5112 KB Output is correct
123 Correct 12 ms 5496 KB Output is correct
124 Correct 31 ms 7644 KB Output is correct
125 Correct 53 ms 9464 KB Output is correct
126 Correct 11 ms 6008 KB Output is correct
127 Correct 23 ms 7160 KB Output is correct
128 Correct 139 ms 13876 KB Output is correct
129 Correct 103 ms 11768 KB Output is correct
130 Correct 91 ms 12152 KB Output is correct
131 Correct 11 ms 5964 KB Output is correct
132 Correct 11 ms 6136 KB Output is correct
133 Correct 483 ms 15068 KB Output is correct
134 Correct 109 ms 9464 KB Output is correct
135 Correct 6 ms 5112 KB Output is correct
136 Correct 39 ms 8312 KB Output is correct
137 Correct 73 ms 9236 KB Output is correct
138 Correct 10 ms 5368 KB Output is correct