Submission #412983

#TimeUsernameProblemLanguageResultExecution timeMemory
412983ChaskaSnowball (JOI21_ho_t2)C++11
100 / 100
244 ms16956 KiB
#include <bits/stdc++.h> 
#define pb push_back
#define sp " "
#define sl "\n"
#define fi first
#define se second
#define mp make_pair
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define rev(a) reverse(a.begin(),a.end())
#define PI 3.141592
#define fo(i,n) for (int i=0;i<n;i++)
#define fofo(i,n,j,m) for (int i=0;i<n;i++) for (int j=0;j<m;j++) 
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N=2e5+5,mod=1e9+7;

ll n,q,a[N],w[N],acu,tam[N];
ll X[N],Y[N];
vector<pair<ll,ll>> group; // sortear por fi
ll res[N];

int main() { 
	cin.tie(0); cout.tie(0); 
	ios_base::sync_with_stdio();
	cin >> n >> q;
	fo(i,n) 
		cin >> a[i];
	fo(i,q) 
		cin >> w[i];
	ll x,y;
	x=y=0;
	fo(i,q) {
		acu += w[i];
		if (acu < x) x = acu;
		if (acu > y) y = acu;
		tam[i] = abs(x) + abs(y);
		
		X[i] = abs(x);
		Y[i] = abs(y);
  	}
	for (int i=0;i<n-1;i++) {
		ll p = a[i+1]-a[i];
		// tam del seg
		// do the bin ? 
		bool y = false;

				long long pp = 2e5;
				long long xd = -1;
				while (pp) { 	
					if (xd+pp<q && xd+pp >= 0 && tam[xd+pp]<p) {
						xd += pp;
					
					} else {
						pp /=2;
					}
				}

				int j = xd;
				
				j++;
				//cout << j << " ";
				if (j==0) {
					if (w[0]>=0)
						res[i] += p;
					else res[i+1] += p;
				} else {
				res[i] += Y[j-1];
				res[i+1] += X[j-1];
				p -= tam[j-1];
				if (j<q && w[j]>=0)
					res[i] += p;
				else 
					if (j<q) res[i+1] += p;
				}
		
		
	}
	res[0] += X[q-1];
	res[n-1] += Y[q-1];
	fo(i,n) cout << res[i] << "\n";
	return 0;
}
// Recuerda limites 
// Recuerda casos especiales

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:52:8: warning: unused variable 'y' [-Wunused-variable]
   52 |   bool y = false;
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...