✅ P7910 76pts (TLE)
This commit is contained in:
		
							
								
								
									
										6
									
								
								insert-sort/data.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								insert-sort/data.in
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
3 4
 | 
			
		||||
3 2 1
 | 
			
		||||
2 3
 | 
			
		||||
1 3 2
 | 
			
		||||
2 2
 | 
			
		||||
2 3
 | 
			
		||||
							
								
								
									
										38
									
								
								insert-sort/main.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								insert-sort/main.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
// The question want me to impl a sort by my self
 | 
			
		||||
// But absolutely not
 | 
			
		||||
 | 
			
		||||
#include <iostream>
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    int n, Q;
 | 
			
		||||
    cin >> n >> Q;
 | 
			
		||||
    int arr[n + 5];
 | 
			
		||||
 | 
			
		||||
    for (int i = 1; i <= n; i++) {
 | 
			
		||||
        cin >> arr[i];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; i < Q; i++) {
 | 
			
		||||
        int op;
 | 
			
		||||
        cin >> op;
 | 
			
		||||
        if (op == 1) {
 | 
			
		||||
            int x, v;
 | 
			
		||||
            cin >> x >> v;
 | 
			
		||||
            arr[x] = v;
 | 
			
		||||
        } else {
 | 
			
		||||
            int xn;
 | 
			
		||||
            cin >> xn;
 | 
			
		||||
            int it = arr[xn];
 | 
			
		||||
            int pos = n;
 | 
			
		||||
            for (int j = 1; j < xn; j++) {
 | 
			
		||||
                if (arr[j] > it) pos--;
 | 
			
		||||
            }
 | 
			
		||||
            for (int j = xn + 1; j <= n; j++) {
 | 
			
		||||
                if (arr[j] >= it) pos--;
 | 
			
		||||
            }
 | 
			
		||||
            cout << pos << endl;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user