#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<pair<int,int> >&a,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,r,p,i+1,c,nec,u,(j*a[i].second)%mod);
p[i]=true;
per(a,r,p,i+1,c+1,nec,u,(j*a[i].first)%mod);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n,c,q,p,l,r;
cin>>n>>c;
vector<pair<int,int> >a(n);
for(int i=0;i<n;i++){
cin>>a[i].first;
}
for(int i=0;i<n;i++){
cin>>a[i].second;
}
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].first=l;
re=1;
for(int k=0;k<n;k++){
re*=a[k].first;
re=re%mod;
}
}
else{
a[p-1].first=l;
a[p-1].second=r;
re=0;
per(a,re,pr,0,0,c,0,1);
}
cout<<re%mod<<"\n";
}
else if( a[p-1].first==l && a[p-1].second==r){
cout<<re%mod<<"\n";
}
else if(n==c){
re/=a[p-1].first;
re*=l;
a[p-1].first=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].first;
todo[i].second*=l;
todo[i].second%=mod;
}
else{
todo[i].second/=a[p-1].second;
todo[i].second*=r;
todo[i].second%=mod;
}
re+=todo[i].second;
}
cout<<re%mod<<"\n";
}
}
return 0;
}
Compilation message
relativnost.cpp: In function 'void per(std::vector<std::pair<int, int> >&, int&, std::vector<bool>&, int, int, int, int, int)':
relativnost.cpp:12:5: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | if(u==a.size()){
| ~^~~~~~~~~~
relativnost.cpp: In function 'int main()':
relativnost.cpp:77:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::vector<bool>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(int i=0;i<todo.size();i++){
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
152 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Runtime error |
165 ms |
65540 KB |
Execution killed with signal 9 |
3 |
Runtime error |
1316 ms |
65540 KB |
Execution killed with signal 9 |
4 |
Runtime error |
56 ms |
65540 KB |
Execution killed with signal 9 |
5 |
Runtime error |
64 ms |
65540 KB |
Execution killed with signal 9 |
6 |
Runtime error |
153 ms |
65536 KB |
Execution killed with signal 9 |
7 |
Runtime error |
56 ms |
65536 KB |
Execution killed with signal 9 |
8 |
Runtime error |
59 ms |
65536 KB |
Execution killed with signal 9 |
9 |
Runtime error |
60 ms |
65540 KB |
Execution killed with signal 9 |
10 |
Runtime error |
440 ms |
65540 KB |
Execution killed with signal 9 |