Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define ull unsigned ll
- #define nl "\n"
- #define sz(x) int(x.size())
- #define NumOfDigit(w) log10(w) + 1
- #define fill(arr, val) memset(arr, val , sizeof(arr))
- #define PI 3.141592654
- #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define fi first
- #define se second
- #define cin(v) for (auto&i:v) cin >> i;
- #define cout(v) for (auto&i:v) cout << i << " ";
- #define fixed(n) fixed << setprecision(n)
- #define MOD 1000000007
- void IO(){
- ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
- }
- void files(){
- //freopen("filename.in" , "r" ,stdin);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
- #endif
- }
- int sum_digit(int n ){
- int ans =0;
- while(n) ans+=n%10 , n/=10;
- return ans ;
- }
- void solve(){
- int n , q ;
- cin >> n >> q;
- vector < int > v(n) , pa(n+1);
- cin(v);
- int freq[n+1]{};
- while(q--){
- int t; cin >> t;
- if(t==2) {
- int x; cin >> x;
- x--;
- bool flag =1;
- int cnt= freq[x];
- if(cnt==0) {
- cout << v[x] << nl;
- continue;
- }
- while(cnt--){
- if(v[x] < 10) {
- flag =0;
- cout << v[x] << nl;
- break;
- }else {
- v[x]= sum_digit(v[x]);
- }
- }
- if(flag) cout << v[x] << nl;
- freq[x]=0;
- }
- else{
- int l ,r ;
- cin >> l >> r ;
- l-- , r--;
- for(int i=l ; i<=r;i++) freq[i]++;
- }
- }
- }
- int main(){
- IO();
- //files();
- int testCase=1; // one test case
- cin >> testCase ;
- while(testCase--)
- solve(); // my code
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement