Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <set>
- #include <string>
- #include <algorithm>
- using namespace std;
- using ll = long long;
- using ld = long double;
- void cv(vector <ll> v){
- for (auto x: v) cout<<x<<' ';
- cout<<'\n';
- }
- vector <ll> rv(1);
- vector <vector <ll> > rt(1);
- int n=1,p=1;
- vector <ll> S;
- ll sz = 1, sq = 1;
- void make(){
- cout<<"river\n";
- cv(rv);
- cout<<"making rt\n";
- sz = sqrt(n);
- sq = sqrt(n);
- while (sz * sq < n){
- sz++;
- }
- cout<<"sz= "<<sz<<'\n';
- cout<<"sq= "<<sq<<"\n";
- rt.resize(sz);
- S.resize(sz, 0);
- for (int i=0;i<sz;++i){
- rt[i].resize(sq);
- }
- rt[sz-1].resize(sq - (sz*sq - n));
- cout<<"rt: size = "<<rt.size()<<" "<<rt[0].size()<<"\n";
- for (int i = 0; i < sz; ++i){
- cout<<"i = "<<i<<"\n";
- cout<<"rt[i].size()= "<<rt[i].size()<<"\n";
- for (int j = 0; i * sq + j < n && j < sq; ++j){
- cout<<"j= "<<j<<"\n";
- int id = i * sq + j;
- cout<<"id = "<<id<<"\n";
- rt[i][j] = rv[id];
- cout<<"rt[i][j]= "<<rt[i][j]<<"\n";
- S[i] += rv[id] * rv[id];
- }
- }
- cout<<"rt made\n";
- for (int i = 0;i<rt.size();++i){
- cout<<"i = "<<i<<"\n";
- cout<<"size= "<<rt[i].size()<<"\n";
- for(int j=0;j<rt[i].size();++j){
- cout<<rt[i][j]<<" ";
- }cout<<"\n";
- }cout<<"\n";
- cout<<"S\n";
- cv(S);
- }
- void bnk(int id){
- int prt_id = id / sq;
- int ix = id - prt_id * sq;
- cout<<"prt_id = "<<prt_id<<" ix = "<<ix<<"\n";
- ll L = rt[prt_id][ix] / 2;
- ll R = rt[prt_id][ix] - L;
- cout<<"LR= "<<L<<' '<<R<<"\n";
- //предусмотреть случай, когда эта штука пустеет и нужно переходить в следующую
- if (rt[prt_id].size() == 1){
- cout<<"ZERO\n";
- if (prt_id == 0){
- cout<<"Z-one\n";
- rt[prt_id+1][0] += (L + R);
- S[prt_id+1] += L*L + R*R;
- }else if (prt_id == rt.size()-1){
- cout<<"Z-two\n";
- rt[prt_id-1][ rt[prt_id-1].size() - 1 ] += (L + R);
- S[prt_id-1] += L*L + R*R;
- }
- else{
- cout<<"Z-three\n";
- rt[prt_id+1][0] += R;
- S[prt_id+1] += R*R;
- rt[prt_id-1][ rt[prt_id-1].size() - 1 ] += L;
- S[prt_id-1] += L*L;
- }
- rt.erase(rt.begin() + prt_id);
- S.erase(S.begin() + prt_id);
- }
- else if (ix > 0 && ix < rt[prt_id].size()-1){
- cout<<"ONE\n";
- S[prt_id] -= rt[prt_id][ix] * rt[prt_id][ix];
- S[prt_id] -= rt[prt_id][ix-1] * rt[prt_id-1][ix];
- S[prt_id] -= rt[prt_id][ix+1] * rt[prt_id+1][ix];
- rt[prt_id][ix-1] += L;
- S[prt_id] += rt[prt_id][ix-1] * rt[prt_id-1][ix];
- rt[prt_id][ix+1] += R;
- S[prt_id] += rt[prt_id][ix+1] * rt[prt_id+1][ix];
- rt[prt_id].erase(rt[prt_id].begin() + ix);
- cv(rt[prt_id]);
- } else if (ix == 0){
- cout<<"TWO\n";
- S[prt_id] -= rt[prt_id][ix] * rt[prt_id][ix];
- S[prt_id] -= rt[prt_id][ix+1] * rt[prt_id+1][ix];
- rt[prt_id][ix+1] += (R + L);
- S[prt_id] += rt[prt_id][ix+1] * rt[prt_id+1][ix];
- rt[prt_id].erase(rt[prt_id].begin());
- cv(rt[prt_id]);
- } else {
- cout<<"THREE\n";
- S[prt_id] -= rt[prt_id][ix] * rt[prt_id][ix];
- S[prt_id] -= rt[prt_id][ix-1] * rt[prt_id-1][ix];
- rt[prt_id][ix-1] += (R + L);
- S[prt_id] += rt[prt_id][ix-1] * rt[prt_id-1][ix];
- rt[prt_id].erase(rt[prt_id].end()-1);
- cv(rt[prt_id]);
- }
- }
- /*осталось создать методы:
- (1) если размер какого-то из векторов в векторе стал больше чем 2*sqrt(n), то поделить вектор на 2 вектора;
- (2)dv() - делать один отрезок реки на 2 отрезка и соответствующий пересчёт
- Потом надо это протестить, продебажить и получить OK
- */
- void dv(int id){
- }
- /*
- 10
- 0 1 2 3 4 5 6 7 8 9
- */
- int main()
- {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- //cin>>n>>p;
- cin>>n;
- rv.resize(n);
- //for (auto &x: rv) cin>>x;
- for (int i=0;i<n;++i){
- rv[i] = i;
- }
- make();
- int k;
- cin>>k;
- for (int i=0;i<k;++i){
- int e,v;
- cin>>e>>v;
- //v--;
- if (e == 1){
- bnk(v);
- }
- else {
- dv(v);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement