F. Counter RMQ
#include<bits/stdc++.h>
using namespace std;
int main()
{
int ts,cs=1;
cin>>ts;
while(ts--)
{
int n,q,ar[20005]={0},i,j,a,b,x;
cin>>n>>q;
for(i=1;i<=q;i++)
{
cin>>a>>b>>x;
for(j=a;j<=b;j++)
{
ar[j]=max(ar[j],x);
}
}
printf("Case %d:",cs++);
for(i=1;i<=n;i++)
{
if(ar[i]==0)
{
ar[i]=20000;
}
cout<<" "<<ar[i];
}
cout<<endl;
}
return 0;
}
I. Gadgets of Tomishu
#include <bits/stdc++.h>
#define sf1(a) scanf("%ld",&a)
#define sf2(a,b) scanf("%ld%ld",&a,&b);
#define sf3(a,b,c) scanf("%ld%ld%ld",&a,&b,&c);
using namespace std;
main()
{
long ts,cs=1;
sf1(ts);
while(ts--)
{
long long i,ans,ar[100010]={0};
long long n,k,mod;
cin>>n>>k>>mod;
//ar[0]=k%mod;
ar[1]=((k%mod)*(k%mod))%mod ;
ar[2]= ((ar[1]%mod) * (k%mod));
for(i=3;i<=n;i++)
{
ar[i]=((ar[i-1]%mod) * (ar[i-2]%mod))%mod;
//cout<<ar[i]<<" "<<ar[i-1]<<" "<<ar[i-2]<<endl;
}
ans=ar[n];
printf("Case %ld: %lld\n",cs++,ans);
}
}