# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
382983 | victoriad | Relativnost (COCI15_relativnost) | C++14 | 1325 ms | 65540 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <fstream>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
int mod=10007;
vector<pair<vector<bool>,int> > todo;
void per(vector<int>&a,vector<int>&b,int & r,vector<bool>&p,int i,int c,int nec,int u,int j){
if(u==a.size()){
if(c>=nec){
r+=j;
r=r%mod;
todo.push_back(make_pair(p,j));
}
return;
}
u++;
p[i]=false;
per(a,b,r,p,i+1,c,nec,u,(j*b[i])%mod);
p[i]=true;
per(a,b,r,p,i+1,c+1,nec,u,(j*a[i])%mod);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n,c,q,p,l,r;
cin>>n>>c;
vector<int >a(n);
vector<int>b(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cin>>b[i];
}
cin>>q;
int re;
for(int i=0;i<q;i++){
vector<bool>pr(n,false);
cin>>p>>l>>r;
if(i==0){
if(c==n){
a[p-1]=l;
re=1;
for(int k=0;k<n;k++){
re*=a[k];
re=re%mod;
}
}
else{
a[p-1]=l;
b[p-1]=r;
re=0;
per(a,b,re,pr,0,0,c,0,1);
}
cout<<re%mod<<"\n";
}
else if(i!=0 && a[p-1]==l&& b[p-1]==r){
cout<<re%mod<<"\n";
}
else if(n==c){
re/=a[p-1];
re*=l;
a[p-1]=l;
cout<<re%mod<<"\n";
}
else{
re=0;
for(int i=0;i<todo.size();i++){
if(todo[i].first[p-1]){
todo[i].second/=a[p-1];
todo[i].second*=l;
todo[i].second%=mod;
}
else{
todo[i].second/=b[p-1];
todo[i].second*=r;
todo[i].second%=mod;
}
re+=todo[i].second;
}
cout<<re%mod<<"\n";
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |