Cod sursa(job #1791994)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 29 octombrie 2016 22:05:09
Problema Fibo3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

constexpr ll maxval = 2 * 1000ll * 1000 * 1000 * 1000 *1000 + 10;

vector<ll> fibos;

void init(){
	fibos.push_back(1);
	ll f0 = 1, f1 = 1;
	while(f1 < maxval){
		ll tmp = f1+f0;
		f0 = f1, f1 = tmp;
		fibos.push_back(f1); }
	fibos.push_back(maxval); }

ll query(ll x, ll y){
	if(x < 0 || y < 0) return 0;
	if(x > y) swap(x, y);
	ll r = 0;
	auto it = begin(fibos);
	for( ; *it <= x; ++it){
		r += *it + 1; }
	for( ; *it <= y; ++it){
		r += x + 1; }
	for( ; *it <= x+y; ++it){
		r += (x+y) - *it + 1; }

	return r; }

ll query(ll x1, ll y1, ll x2, ll y2){
	return query(x2, y2) - query(x2, y1-1) - query(x1-1, y2) + query(x1-1, y1-1); }

int main(){
	init();
	ifstream f("fibo3.in");
	ofstream g("fibo3.out");
	int t;
	f >> t;
	for(ll x1, y1, x2, y2; t--; ){
		f >> x1 >> y1 >> x2 >> y2;
		g << query(x1, y1, x2, y2) << '\n'; }
	return 0; }