T1: Matrix Games
Just look at the title look ignorant, I feel a little have no idea ......
And then began to look at the subject, it seems to identify problems described hiding something? ? ?
Idle, bored crazy feeling topic describes a very simple thing, as if to suggest something!
So put title equation write down - $ (i-1) * m + j $
Then the answer to this formula represented - $ \ sum_ {i = 1} ^ nR_i \ sum_ {j = 1} ^ mS_j [(i-1) * m + j] $
Then the item with a $ I $ can be ripped out of $ O (n) $ done
so,code
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #include<vector> 7 #define ll long long 8 using namespace std; 9 const int MAXN=1000005,MAXK=100005,D=1e9+7; 10 int n,m,k; 11 ll sums,sumr,s[MAXN],r[MAXN],ans,tmp,sum; 12 char opt[5]; 13 int main() { 14 scanf("%d%d%d",&n,&m,&k); 15 for(int i=1;i<=m;i++) s[i]=1; 16 for(int i=1;i<=n;i++) r[i]=1; 17 for(int i=1;i<=k;i++) { 18 ll x,y; 19 scanf("%s%lld%lld",opt,&x,&y); 20 if(opt[0]=='R') r[x]=r[x]*y%D; 21 else s[x]=s[x]*y%D; 22 } 23 for(int i=1;i<=m;i++) sums=(sums+s[i])%D; 24 for(int i=1;i<=m;i++) tmp=(tmp+s[i]*i)%D; 25 for(int i=1;i<=n;i++) ans=(ans+(tmp+(ll)(i-1)*m%D*sums)%D*r[i]%D)%D; 26 printf("%lld\n",(ans%D+D)%D); 27 return 0; 28 }
T2: Hopscotch
See the range of k matrix multiplication first thought, but looked n and m or forget
Found that most changes will only affect the previous operation three points, so even violent side run,
Also found that if a graph is built of n points, n edges directed graph, it shall be a ring inward of the tree
It is easy to think of the time when a lot of k is always around the ring, so you can take it to the length of the ring mold, the complexity of the almost
T3: beautiful sequence