Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
12535
//g++ 5.4.0 #include <iostream> #include <vector> #define MAXTAM 1000 using namespace std; vector<int> ft(MAXTAM), ftC(MAXTAM); vector<int> entradas; int LSOne(int n) { return n&(-n); } void actualizaN(int n,int valor) { while(n<MAXTAM) { ft[n]+=valor; n+=LSOne(n); } } int consultaN(int a) { int suma; suma = 0; while(a) { suma+=ft[a]; a-=LSOne(a); } return suma; } void actualizaC(int n,int valor) { while(n<MAXTAM) { ftC[n]+=valor; n+=LSOne(n); } } int consultaC(int a) { int suma; suma = 0; while(a) { suma+=ftC[a]; a-=LSOne(a); } return suma; } int main() { int N, K; int num; char inst; int ind, val; int cc, cn; int a, b; while(cin>>N) { entradas.clear(); entradas.push_back(0); cin>>K; for(int i=1; i<=N; i++) { cin>>num; entradas.push_back(num); if(num<0) actualizaN(i, 1); if(num==0) actualizaC(i, 1); } /* cout<< "\nEntradas I: "; for(auto a: entradas) cout<< a; cout<<"\n"; */ for(int i=1; i<=K; i++) { cin>>inst; cin>>ind; cin>>val; if(inst == 'C') { if(entradas[ind]<0 and val>0) actualizaN(ind, -1); else if(entradas[ind]>0 and val<0) actualizaN(ind, +1); else if(entradas[ind]==0 and val!=0) actualizaC(ind, -1); else if(entradas[ind]!=0 and val==0) actualizaC(ind, +1); else if(entradas[ind]==0 and val<0) { actualizaN(ind, +1); actualizaC(ind, -1); } else if(entradas[ind]<0 and val==0) { actualizaN(ind, -1); actualizaC(ind, +1); } entradas[ind] = val; /* cout<< "\nConsulta N: "; for(int i=1; i<=N; i++) cout<< consultaN(i); cout<< "\nConsulta C: "; for(int i=1; i<=N; i++) cout<< consultaC(i); cout<< "\nEntradas: "; for(auto a: entradas) cout<< a; cout<<"\n";*/ } if(inst == 'P') { if(ind==1) { cc = consultaC(val); cn = consultaN(val); }else { cc = consultaC(val) - consultaC(ind-1); cn = consultaN(val) - consultaN(ind-1); } if(cn%2 == 0 and cc==0) cout<<"+"; else if(cn%2 == 1 and cc==0) cout<<"-"; else if(cc>0) cout<<"0"; } } printf("\n"); for(int i=0; i<MAXTAM; i++) { ft[i]=0; ftC[i]=0; } } }
run
|
edit
|
history
|
help
0
Microsoft Question - MaxEmployeeAttendence (original question)
ThreadContext
Dar
process memory structure
ReplaceGreaterSum in BST
inheritance test
Undefined behaviour
Get smallest dividers
Valuing Fixed Income Investments
template example