Submission #236692

# Submission time Handle Problem Language Result Execution time Memory
236692 2020-06-02T21:34:54 Z super_j6 Fibonacci representations (CEOI18_fib) C++14
100 / 100
346 ms 26732 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <iterator>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int mod = 1000000007;

struct T{
	int l, r, d;
	struct M{
		ll aa, ab, ba, bb;
		
		M() : aa(1), ab(0), ba(0), bb(1) {}
		M(int aa, int ab, int ba, int bb) :
			aa(aa), ab(ab), ba(ba), bb(bb) {}
		M(int x, int y){
			aa = ab = max(0, (x - 1) / 2);
			ba = bb = !(x & 1);
			aa = (y * aa + 1) % mod, ba *= y;
		}
		
		M operator*(M m){
			return M((aa * m.aa + ab * m.ba) % mod, 
				(aa * m.ab + ab * m.bb) % mod,
				(ba * m.aa + bb * m.ba) % mod,
				(ba * m.ab + bb * m.bb) % mod);
		}
	} m;
	
	T() : d(0){}
	T(pi p) : l(p.f + 1), r(p.s - 1), d((p.s - p.f) / 2) {}
	
	friend T operator + (T a, T b){
		if(!a.d) return b;
		if(!b.d) return a;
		T ret = a;
		ret.r = b.r;
		ret.m = a.m * M(b.l - a.r, b.d) * b.m;
		return ret;
	}
};

const int maxn = 1 << 17;
int n;
T tre[maxn << 1];

//update 0101010 ranges
vector<int> id;
vector<pi> q[maxn];
set<pi> s;

void add(int t, pi p){
	id.push_back(p.f);
	q[t].push_back(p);
	s.insert(p);
}

void del(int t, set<pi>::iterator it){
	q[t].push_back(*it);
	s.erase(it);
}

void add(int t, int x){
	pi p = {x - 1, x + 1};
	auto it = s.lower_bound({x, 2e9});
	if(it == s.begin() || prev(it)->s < x){
		if(it != s.begin() && prev(it)->s + 1 == x){
			p.f = prev(it)->f;
			del(t, prev(it));
		}
		if(it->f - 1 == x){
			p.s = it->s;
			del(t, it);	
		}
		add(t, p);
	}else{
		it--;
		if((x - it->f) & 1){
			p = {it->f + 1, x};
			x = it->s;
			del(t, it);
			if(p.f < p.s) add(t, p);
			if(p.f >= 2) add(t, max(1, p.f - 2));
			add(t, x);
		}else{
			p = {it->f, min(x, it->s - 2)};
			x = max(x + 1, it->s);
			del(t, it);
			if(p.f < p.s) add(t, p);
			add(t, x);
		}
	}
}
//end update 0101010 ranges

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		add(i, x);
	}
	
	sort(id.begin(), id.end());
	id.erase(unique(id.begin(), id.end()), id.end());
	
	for(int i = 0; i < n; i++){
		for(pi p : q[i]){
			int x = lower_bound(id.begin(), id.end(), p.f) - id.begin() + maxn;
			tre[x] = tre[x].d ? T() : T(p);
			for(x >>= 1; x; x >>= 1){
				tre[x] = tre[x << 1] + tre[x << 1 | 1];
			}
		}
		cout << (T::M(tre[1].l, tre[1].d) * tre[1].m).aa << endl;
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 15744 KB Output is correct
2 Correct 12 ms 15744 KB Output is correct
3 Correct 12 ms 15776 KB Output is correct
4 Correct 12 ms 15744 KB Output is correct
5 Correct 12 ms 15744 KB Output is correct
6 Correct 12 ms 15744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 15744 KB Output is correct
2 Correct 12 ms 15744 KB Output is correct
3 Correct 12 ms 15776 KB Output is correct
4 Correct 12 ms 15744 KB Output is correct
5 Correct 12 ms 15744 KB Output is correct
6 Correct 12 ms 15744 KB Output is correct
7 Correct 12 ms 15744 KB Output is correct
8 Correct 12 ms 15744 KB Output is correct
9 Correct 12 ms 15744 KB Output is correct
10 Correct 13 ms 15744 KB Output is correct
11 Correct 12 ms 15744 KB Output is correct
12 Correct 12 ms 15744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 15744 KB Output is correct
2 Correct 12 ms 15744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 15744 KB Output is correct
2 Correct 12 ms 15744 KB Output is correct
3 Correct 12 ms 15776 KB Output is correct
4 Correct 12 ms 15744 KB Output is correct
5 Correct 12 ms 15744 KB Output is correct
6 Correct 12 ms 15744 KB Output is correct
7 Correct 12 ms 15744 KB Output is correct
8 Correct 12 ms 15744 KB Output is correct
9 Correct 12 ms 15744 KB Output is correct
10 Correct 13 ms 15744 KB Output is correct
11 Correct 12 ms 15744 KB Output is correct
12 Correct 12 ms 15744 KB Output is correct
13 Correct 12 ms 15744 KB Output is correct
14 Correct 12 ms 15744 KB Output is correct
15 Correct 12 ms 15744 KB Output is correct
16 Correct 12 ms 15744 KB Output is correct
17 Correct 12 ms 15744 KB Output is correct
18 Correct 12 ms 15744 KB Output is correct
19 Correct 12 ms 15744 KB Output is correct
20 Correct 12 ms 15744 KB Output is correct
21 Correct 12 ms 15744 KB Output is correct
22 Correct 12 ms 15744 KB Output is correct
23 Correct 12 ms 15744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 15744 KB Output is correct
2 Correct 209 ms 25012 KB Output is correct
3 Correct 205 ms 24048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 15744 KB Output is correct
2 Correct 12 ms 15744 KB Output is correct
3 Correct 12 ms 15776 KB Output is correct
4 Correct 12 ms 15744 KB Output is correct
5 Correct 12 ms 15744 KB Output is correct
6 Correct 12 ms 15744 KB Output is correct
7 Correct 12 ms 15744 KB Output is correct
8 Correct 12 ms 15744 KB Output is correct
9 Correct 12 ms 15744 KB Output is correct
10 Correct 13 ms 15744 KB Output is correct
11 Correct 12 ms 15744 KB Output is correct
12 Correct 12 ms 15744 KB Output is correct
13 Correct 12 ms 15744 KB Output is correct
14 Correct 12 ms 15744 KB Output is correct
15 Correct 12 ms 15744 KB Output is correct
16 Correct 12 ms 15744 KB Output is correct
17 Correct 12 ms 15744 KB Output is correct
18 Correct 12 ms 15744 KB Output is correct
19 Correct 12 ms 15744 KB Output is correct
20 Correct 12 ms 15744 KB Output is correct
21 Correct 12 ms 15744 KB Output is correct
22 Correct 12 ms 15744 KB Output is correct
23 Correct 12 ms 15744 KB Output is correct
24 Correct 12 ms 15744 KB Output is correct
25 Correct 209 ms 25012 KB Output is correct
26 Correct 205 ms 24048 KB Output is correct
27 Correct 60 ms 18552 KB Output is correct
28 Correct 94 ms 20340 KB Output is correct
29 Correct 67 ms 18292 KB Output is correct
30 Correct 95 ms 20212 KB Output is correct
31 Correct 138 ms 20716 KB Output is correct
32 Correct 130 ms 20976 KB Output is correct
33 Correct 162 ms 21228 KB Output is correct
34 Correct 122 ms 21100 KB Output is correct
35 Correct 179 ms 21104 KB Output is correct
36 Correct 213 ms 21160 KB Output is correct
37 Correct 173 ms 21208 KB Output is correct
38 Correct 220 ms 25968 KB Output is correct
39 Correct 86 ms 20212 KB Output is correct
40 Correct 129 ms 21356 KB Output is correct
41 Correct 244 ms 22744 KB Output is correct
42 Correct 204 ms 25868 KB Output is correct
43 Correct 150 ms 23144 KB Output is correct
44 Correct 195 ms 26732 KB Output is correct
45 Correct 317 ms 26596 KB Output is correct
46 Correct 217 ms 26468 KB Output is correct
47 Correct 273 ms 26384 KB Output is correct
48 Correct 288 ms 26728 KB Output is correct
49 Correct 346 ms 26724 KB Output is correct
50 Correct 234 ms 25940 KB Output is correct