Submission #1220046

#TimeUsernameProblemLanguageResultExecution timeMemory
1220046kokoxuyaXylophone (JOI18_xylophone)C++20
100 / 100
26 ms448 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define pii pair<int,int> #define ss second #define ff first #define piii pair<int,pii> #define debu(x) (cerr << #x << " = "<< x << "\n") #define debu2(x,y) (cerr << #x << " = "<< x << " " << #y << " = " << y << "\n") #define debu3(x,y,z) (cerr << #x << " = "<< x << " " << #y << " = " << y << " " << #z << " = " << z<< "\n") #define bitout(x,y) {\ cerr << #x << " : ";\ for (int justforbits = y; justforbits >=0; justforbits--)cout << (((1 << justforbits) & x)>=1);\ cout << "\n";\ } #define rangeout(j,rangestart,rangeend) {\ cerr << "outputting" << #j<< ":\n";\ for (int forrang = rangestart; forrang <= rangeend; forrang++)cerr << j[forrang] << " ";\ cerr<<"\n";\ } #define c1 {cerr << "Checkpoint 1! \n\n";cerr.flush();} #define c2 {cerr << "Checkpoint 2! \n\n";cerr.flush();} #define c3 {cerr << "Checkpoint 3! \n\n";cerr.flush();} #define c4 {cerr << "Checkpoint 4! \n\n";cerr.flush();} //don't use LLONG_MIN/MAX bc this is an intearctive and you don't have #define int long long void solve(int N) { int t1,t2,t3,t4; vector<int>wentup; wentup.pb(0);wentup.pb(0); t1=query(1,2); wentup.pb(t1); for(int a=3;a<=N;a++) { t1=query(a-1,a); t2=query(a-2,a); if(abs(t1-t2)==abs(wentup[a-2]-wentup[a-1])) { t1*=(wentup[a-2]<wentup[a-1]?1:-1); } else { t1*=(wentup[a-2]<wentup[a-1]?-1:1); } wentup.pb(wentup[a-1]+t1); } //rangeout(wentup,1,N); pii maxval=mp(INT_MIN,0),minval=mp(INT_MAX,0); for(int a=1;a<=N;a++) { //debu2(wentup[a],a); maxval=max(maxval,mp(wentup[a],a)); //debu2(minval.ff,wentup[a]); minval=min(minval,mp(wentup[a],a)); } //debu2(maxval.ss,minval.ss); int smallest,mul; if(maxval.ss<minval.ss) { mul=-1; smallest=maxval.ss; } else { mul=1; smallest=minval.ss; } //debu(smallest); for(int a=1;a<=N;a++)wentup[a]*=mul; vector<int>ans(N+1); for(int a=1;a<=N;a++) { t1=1+wentup[a]-wentup[smallest]; //debu3(wentup[a],wentup[smallest],a); //debu2(t1,a); ans[a]=t1; } //rangeout(ans,1,N); for(int a=1;a<=N;a++) { answer(a,ans[a]); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...